Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building Error #4581

Open
dmerniestic1987 opened this issue Feb 7, 2024 · 9 comments
Open

Building Error #4581

dmerniestic1987 opened this issue Feb 7, 2024 · 9 comments
Assignees
Labels
investigate Under investigation and may be a bug. v5 Issues regarding legacy-v5

Comments

@dmerniestic1987
Copy link

Ethers Version

5.7.2

Search Terms

fallback provider

Describe the Problem

We found a building error when using FallBackProvider. We can not build our project with different versions of ethers.js: 5.7.2, 5.7.1, 5.7.0 and 5.4.0
When running npm run build, it throws the following error:

node_modules/@ethersproject/providers/src.ts/base-provider.ts:1804:25 - error TS2365: Operator '>' cannot be applied to types 'number' and 'string | number'.

1804                     if (blockNumber > this._emitted.block) { return null; }

Code Snippet

export class FallbackProviderClient {
  private readonly settingsArray: CommonClientSettings[];
  private readonly web3: FallbackProvider;
  private readonly logger: Logger = new Logger(FallbackProviderClient.name);

  constructor(settings: CommonClientSettings[]) {
    this.settingsArray = settings;
    this.web3 = this.createFallBackProvider();
  }

  createFallBackProvider(): FallbackProvider {
    const fallBackProviderConfigs: FallbackProviderConfig[] =
      this.settingsArray.map((commonClientSettings) => {
        return {
          priority: commonClientSettings.priority,
          provider: RpcHelper.createJsonRpcProvider(commonClientSettings),
          weight: 1,
          stallTimeout: 6000,
        } as FallbackProviderConfig;
      });
    return new ethers.providers.FallbackProvider(fallBackProviderConfigs, 1);
  }
}

Contract ABI

No response

Errors

node_modules/@ethersproject/providers/src.ts/base-provider.ts:1804:25 - error TS2365: Operator '>' cannot be applied to types 'number' and 'string | number'.

1804                     if (blockNumber > this._emitted.block) { return null; }

Environment

node.js (v12 or newer)

Environment (Other)

No response

@dmerniestic1987 dmerniestic1987 added investigate Under investigation and may be a bug. v5 Issues regarding legacy-v5 labels Feb 7, 2024
@ricmoo
Copy link
Member

ricmoo commented Feb 7, 2024

Are you using the correct TypeScript version (using npm install to install the locked version) and with the correct TypeScript settings? That part of the code hasn’t changed and at the time of each release the build worked, since the corresponding dist files were all created from the source. No published versions ever had build errors (as no emit is enabled).

@ricmoo
Copy link
Member

ricmoo commented Feb 7, 2024

This looks like you are trying to use an incompatible TS version, ignoring the Ethers tsconfig.

I recommend specifying skipLibCheck, since packages in node_modules can’t be expected to adhere to the tsconfig in the dependant package.

Does that make sense?

@dmerniestic1987
Copy link
Author

@ricmoo "typescript": "^5.3.3"
The same error is thrown in version ethers-js 6.10.0

@ricmoo
Copy link
Member

ricmoo commented Feb 7, 2024

The other opened issue is referencing v5 code. Not v6. You mean need to blow away your node_modules and package-lock, because there are definitely unrelated packages being pulled in. If in doubt, when looking in the node_modules, check the package.json within that folder. :)

@dmerniestic1987
Copy link
Author

@ricmoo what is the typescript version recommended to version 5.7.2?

@ricmoo
Copy link
Member

ricmoo commented Feb 7, 2024

According to the package.json version 5.0.4. Also note that TypeScript does not follow semver so the following fact same version must be used.

This is also why skipLibCheck is highly recommended in general.

@dmerniestic1987
Copy link
Author

dmerniestic1987 commented Feb 8, 2024

Hi @ricmoo se used tyepscript 5.04 and skipLibCheck is true. It is the compilation error:

node_modules/@ethersproject/providers/src.ts/base-provider.ts:1233:27 - error TS2769: No overload matches this call.
  Overload 1 of 2, '(intervalId: string | number | Timeout): void', gave the following error.
    Argument of type 'Timer' is not assignable to parameter of type 'string | number | Timeout'.
      Property '[Symbol.dispose]' is missing in type 'Timer' but required in type 'Timeout'.
  Overload 2 of 2, '(id: number): void', gave the following error.
    Argument of type 'Timer' is not assignable to parameter of type 'number'.

1233             clearInterval(this._poller);
                               ~~~~~~~~~~~~

  node_modules/@types/node/timers.d.ts:130:17
    130                 [Symbol.dispose](): void;
                        ~~~~~~~~~~~~~~~~
    '[Symbol.dispose]' is declared here.
node_modules/@ethersproject/providers/src.ts/base-provider.ts:1250:27 - error TS2769: No overload matches this call.
  Overload 1 of 2, '(intervalId: string | number | Timeout): void', gave the following error.
    Argument of type 'Timer' is not assignable to parameter of type 'string | number | Timeout'.
  Overload 2 of 2, '(id: number): void', gave the following error.
    Argument of type 'Timer' is not assignable to parameter of type 'number'.

1250             clearInterval(this._poller);
                               ~~~~~~~~~~~~

node_modules/@ethersproject/providers/src.ts/base-provider.ts:1804:25 - error TS2365: Operator '>' cannot be applied to types 'number' and 'string | number'.

1804                     if (blockNumber > this._emitted.block) { return null; }
                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@ethersproject/providers/src.ts/fallback-provider.ts:132:30 - error TS2769: No overload matches this call.
  Overload 1 of 2, '(timeoutId: string | number | Timeout): void', gave the following error.
    Argument of type 'Timer' is not assignable to parameter of type 'string | number | Timeout'.
  Overload 2 of 2, '(id: number): void', gave the following error.
    Argument of type 'Timer' is not assignable to parameter of type 'number'.

132                 clearTimeout(timer);
                                 ~~~~~

tsconfig

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "ES2021",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,
    "esModuleInterop": true
  }
}

package.json dependencies

 "dependencies": {
    "@nestjs/axios": "^3.0.0",
    "@nestjs/cache-manager": "^2.1.0",
    "@nestjs/common": "^10.0.0",
    "@nestjs/core": "^10.0.0",
    "@nestjs/microservices": "^10.1.0",
    "@nestjs/platform-express": "^10.0.0",
    "@nestjs/schedule": "^3.0.1",
    "@nestjs/swagger": "^7.0.12",
    "@nestjs/terminus": "^10.1.1",
    "@nestjs/typeorm": "^10.0.2",
    "@nestjs/websockets": "^10.0.3",
    "axios": "^1.4.0",
    "cache-manager": "^5.2.4",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.14.0",
    "config": "^3.3.9",
    "crypto-js": "^4.1.1",
    "dd-trace": "^3.17.1",
    "dotenv": "^16.3.1",
    "ethers": "^5.7.2",
    "mysql2": "^3.4.3",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^7.8.1",
    "typeorm": "^0.3.17"
  },
    "devDependencies": {
    "@nestjs/cli": "^10.0.0",
    "@nestjs/schematics": "^10.0.0",
    "@nestjs/testing": "^10.0.0",
    "@types/express": "^4.17.17",
    "@types/jest": "^29.5.2",
    "@types/node": "^20.3.1",
    "@types/supertest": "^2.0.12",
    "@typescript-eslint/eslint-plugin": "^6.21.0",
    "@typescript-eslint/parser": "^6.21.0",
    "eslint": "^8.42.0",
    "eslint-config-prettier": "^9.1.0",
    "eslint-plugin-prettier": "^5.1.3",
    "jest": "^29.7.0",
    "prettier": "^3.2.5",
    "source-map-support": "^0.5.21",
    "supertest": "^6.3.4",
    "ts-jest": "^29.1.2",
    "ts-loader": "^9.5.1",
    "ts-node": "^10.9.2",
    "tsconfig-paths": "^4.2.0",
    "typescript": "5.0.4"
  },

@ricmoo
Copy link
Member

ricmoo commented Feb 8, 2024

You will need the @types/node dependency included and possibly add node to the libs in the tsconfig.json.

@dmerniestic1987
Copy link
Author

Hi @ricmoo thanks! But it did not work.

I used node libs and the @types/node but no success result found. Do you see any mistake in the tsconfig?

"@types/node": "^20.11.16",

node_modules/@ethersproject/providers/src.ts/base-provider.ts:1233:27 - error TS2345: Argument of type 'Timer' is not assignable to parameter of type 'string | number | Timeout'.
  Property '[Symbol.dispose]' is missing in type 'Timer' but required in type 'Timeout'.

1233             clearInterval(this._poller);
                               ~~~~~~~~~~~~

  node_modules/@types/node/timers.d.ts:130:17
    130                 [Symbol.dispose](): void;
                        ~~~~~~~~~~~~~~~~
    '[Symbol.dispose]' is declared here.
node_modules/@ethersproject/providers/src.ts/base-provider.ts:1250:27 - error TS2345: Argument of type 'Timer' is not assignable to parameter of type 'string | number | Timeout'.

1250             clearInterval(this._poller);
                               ~~~~~~~~~~~~
node_modules/@ethersproject/providers/src.ts/base-provider.ts:1804:25 - error TS2365: Operator '>' cannot be applied to types 'number' and 'string | number'.

1804                     if (blockNumber > this._emitted.block) { return null; }
                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@ethersproject/providers/src.ts/fallback-provider.ts:132:30 - error TS2345: Argument of type 'Timer' is not assignable to parameter of type 'string | number | Timeout'.

132                 clearTimeout(timer);

Current tsconfig

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "ES2022",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,
    "esModuleInterop": true,
    "moduleResolution": "node16",
    "lib": [
      "es2020",
      "es5",
      "node"
    ]
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Under investigation and may be a bug. v5 Issues regarding legacy-v5
Projects
None yet
Development

No branches or pull requests

2 participants