FuelLabs / fuels-ts

Fuel Network Typescript SDK
https://docs.fuel.network/docs/fuels-ts/
Apache License 2.0
44.06k stars 1.34k forks source link

SDK not compiling on user's projects #1907

Closed arboleya closed 4 months ago

arboleya commented 7 months ago

Repro

node -v &&
  mkdir temp-app && \
  cd temp-app && \
  pnpm init && \
  pnpm add fuels typescript && \
  echo 'import { Fuel } from "fuels"; console.log(Fuel.STORAGE_KEY);' > app.ts && \
  pnpm tsc app.ts

Error Digest

error TS1259: Module '"/temp-app/node_modules/.pnpm/@types+bn.js@5.1.5/node_modules/@types/bn.js/index"' can only be default-imported using the 'esModuleInterop' flag
error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher.
error TS2321: Excessive stack depth comparing types 'PickRestType<ArrayTail<ArrayTail<Destination>>>[number]' and 'UnknownArrayOrTuple'.
error TS2321: Excessive stack depth comparing types 'PickRestType<ArrayTail<ArrayTail<Destination>>>[number]' and 'UnknownRecord'.
error TS2321: Excessive stack depth comparing types 'PickRestType<ArrayTail<ArrayTail<Source>>>[number]' and 'UnknownArrayOrTuple'.
error TS2688: Cannot find type definition file for 'web'.
error TS2688: Cannot find type definition file for 'web'.
error TS4090: Conflicting definitions for 'node' found at '/temp-app/node_modules/.pnpm/@types+node@18.15.13/node_modules/@types/node/index.d.ts' and '/temp-app/node_modules/.pnpm/@types+node@20.11.30/node_modules/@types/node/index.d.ts'. Consider installing a specific version of this library to resolve the conflict.

Full Error

Click to expand ``` node_modules/.pnpm/@fuel-ts+abi-coder@0.77.0/node_modules/@fuel-ts/abi-coder/dist/encoding/coders/v0/ByteCoder.d.ts(3,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/@fuel-ts+abi-coder@0.77.0/node_modules/@fuel-ts/abi-coder/dist/encoding/coders/v0/EnumCoder.d.ts(11,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/@fuel-ts+abi-coder@0.77.0/node_modules/@fuel-ts/abi-coder/dist/encoding/coders/v0/StdStringCoder.d.ts(3,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/@fuel-ts+abi-coder@0.77.0/node_modules/@fuel-ts/abi-coder/dist/encoding/coders/v0/StringCoder.d.ts(3,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/@fuel-ts+abi-coder@0.77.0/node_modules/@fuel-ts/abi-coder/dist/FunctionFragment.d.ts(5,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/@fuel-ts+account@0.77.0_dexie@3.2.7/node_modules/@fuel-ts/account/dist/connectors/types/local-storage.d.ts(1,23): error TS2688: Cannot find type definition file for 'web'. node_modules/.pnpm/@fuel-ts+account@0.77.0_dexie@3.2.7/node_modules/@fuel-ts/account/dist/providers/provider.d.ts(1,23): error TS2688: Cannot find type definition file for 'web'. node_modules/.pnpm/@fuel-ts+account@0.77.0_dexie@3.2.7/node_modules/@fuel-ts/account/dist/providers/provider.d.ts(188,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/@fuel-ts+account@0.77.0_dexie@3.2.7/node_modules/@fuel-ts/account/dist/wallet-manager/vaults/mnemonic-vault.d.ts(10,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/@fuel-ts+account@0.77.0_dexie@3.2.7/node_modules/@fuel-ts/account/dist/wallet-manager/vaults/privatekey-vault.d.ts(9,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/@fuel-ts+account@0.77.0_dexie@3.2.7/node_modules/@fuel-ts/account/dist/wallet-manager/wallet-manager.d.ts(15,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/@fuel-ts+math@0.77.0/node_modules/@fuel-ts/math/dist/bn.d.ts(2,8): error TS1259: Module '"/temp-app/node_modules/.pnpm/@types+bn.js@5.1.5/node_modules/@types/bn.js/index"' can only be default-imported using the 'esModuleInterop' flag node_modules/.pnpm/@fuel-ts+program@0.77.0_dexie@3.2.7/node_modules/@fuel-ts/program/dist/instruction-set.d.ts(6,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/@fuel-ts+transactions@0.77.0/node_modules/@fuel-ts/transactions/dist/coders/byte-array.d.ts(4,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/abi/abi-coder.d.ts(21,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/abi/coders/abstract-coder.d.ts(14,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/abi/coders/abstract-coder.d.ts(96,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/abi/coders/abstract-coder.d.ts(109,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/abi/fragments.d.ts(109,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/abi/interface.d.ts(171,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/abi/typed.d.ts(78,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/contract/wrappers.d.ts(55,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/contract/wrappers.d.ts(71,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/crypto/signature.d.ts(33,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/crypto/signing-key.d.ts(14,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/hash/typed-data.d.ts(50,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/abstract-provider.d.ts(253,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/abstract-signer.d.ts(51,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/ens-resolver.d.ts(90,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/network.d.ts(28,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/plugins-network.d.ts(130,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/plugins-network.d.ts(146,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/provider-browser.d.ts(41,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/provider-etherscan.d.ts(80,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/provider-fallback.d.ts(84,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/provider-ipcsocket.d.ts(1,23): error TS4090: Conflicting definitions for 'node' found at '/temp-app/node_modules/.pnpm/@types+node@18.15.13/node_modules/@types/node/index.d.ts' and '/temp-app/node_modules/.pnpm/@types+node@20.11.30/node_modules/@types/node/index.d.ts'. Consider installing a specific version of this library to resolve the conflict. The file is in the program because: Type library referenced via 'node' from file '/temp-app/node_modules/.pnpm/@fuel-ts+math@0.77.0/node_modules/@fuel-ts/math/dist/bn.d.ts' with packageId '@types/node/index.d.ts@20.11.30' Type library referenced via 'node' from file '/temp-app/node_modules/.pnpm/undici-types@5.26.5/node_modules/undici-types/formdata.d.ts' with packageId '@types/node/index.d.ts@20.11.30' Type library referenced via 'node' from file '/temp-app/node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/provider-ipcsocket.d.ts' with packageId '@types/node/index.d.ts@18.15.13' node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/provider-ipcsocket.d.ts(12,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/provider-jsonrpc.d.ts(212,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/provider-jsonrpc.d.ts(326,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/provider-jsonrpc.d.ts(344,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/provider-socket.d.ts(21,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/provider-socket.d.ts(71,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/provider-socket.d.ts(88,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/provider-websocket.d.ts(31,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/provider.d.ts(269,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/provider.d.ts(514,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/provider.d.ts(687,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/providers/signer-noncemanager.d.ts(11,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/transaction/transaction.d.ts(90,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/utils/events.d.ts(58,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/utils/fetch.d.ts(45,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/utils/fetch.d.ts(66,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/utils/fetch.d.ts(294,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/utils/fixednumber.d.ts(63,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/wallet/base-wallet.d.ts(17,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/wallet/hdwallet.d.ts(27,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/wallet/wallet.d.ts(17,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/wordlists/wordlist-owl.d.ts(15,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/ethers@6.11.1/node_modules/ethers/lib.commonjs/wordlists/wordlist-owla.d.ts(15,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. node_modules/.pnpm/type-fest@3.13.1/node_modules/type-fest/source/merge-deep.d.ts(140,5): error TS2321: Excessive stack depth comparing types 'PickRestType>>[number]' and 'UnknownArrayOrTuple'. node_modules/.pnpm/type-fest@3.13.1/node_modules/type-fest/source/merge-deep.d.ts(140,5): error TS2321: Excessive stack depth comparing types 'PickRestType>>[number]' and 'UnknownRecord'. node_modules/.pnpm/type-fest@3.13.1/node_modules/type-fest/source/merge-deep.d.ts(140,5): error TS2321: Excessive stack depth comparing types 'PickRestType>>[number]' and 'UnknownArrayOrTuple'. node_modules/.pnpm/type-fest@3.13.1/node_modules/type-fest/source/merge-deep.d.ts(166,5): error TS2321: Excessive stack depth comparing types 'PickRestType>>[number]' and 'UnknownArrayOrTuple'. node_modules/.pnpm/type-fest@3.13.1/node_modules/type-fest/source/merge-deep.d.ts(166,5): error TS2321: Excessive stack depth comparing types 'PickRestType>>[number]' and 'UnknownRecord'. node_modules/.pnpm/type-fest@3.13.1/node_modules/type-fest/source/merge-deep.d.ts(166,5): error TS2321: Excessive stack depth comparing types 'PickRestType>>[number]' and 'UnknownArrayOrTuple'. node_modules/.pnpm/type-fest@3.13.1/node_modules/type-fest/source/merge-deep.d.ts(192,5): error TS2321: Excessive stack depth comparing types 'PickRestType>>[number]' and 'UnknownArrayOrTuple'. node_modules/.pnpm/type-fest@3.13.1/node_modules/type-fest/source/merge-deep.d.ts(192,5): error TS2321: Excessive stack depth comparing types 'PickRestType>>[number]' and 'UnknownRecord'. node_modules/.pnpm/type-fest@3.13.1/node_modules/type-fest/source/merge-deep.d.ts(192,5): error TS2321: Excessive stack depth comparing types 'PickRestType>>[number]' and 'UnknownArrayOrTuple'. ```
great9 commented 7 months ago

this happens with 0.77, 0.76 and 0.72 node versions 20 and 18.19.1

great9 commented 7 months ago

also problems with type-fest import in fuels-ts

nedsalk commented 7 months ago

By running pnpm tsc app.ts typescript's default compiler options are used. This still emits the app.js file, but it prints out problems typescript finds in the dependencies - some due to excessive stack depth due to the recursive type generics are programmed, others due to a dependency using >ES2015 features while tsc's default is ES3, etc.

Long story short, running pnpm tsc app.ts --skipLibCheck stops the errors being printed out and the user will get app.js.

However, I'd highly suggest looking into using a tsconfig file and running pnpm tsc -p tsconfig.json. This one is a good starter.

great9 commented 7 months ago

By running pnpm tsc app.ts typescript's default compiler options are used. This still emits the app.js file, but it prints out problems typescript finds in the dependencies - some due to excessive stack depth due to the recursive type generics are programmed, others due to a dependency using >ES2015 features while tsc's default is ES3, etc.

mine is set to es2022

nedsalk commented 7 months ago

@great9 can you share your tsconfig.json contents with us and the full error log that gets produced?

great9 commented 7 months ago

@great9 can you share your tsconfig.json contents with us and the full error log that gets produced?

{
  "$schema": "https://json.schemastore.org/tsconfig",
  "display": "Node 18",
  "target": "es2022",
  "compilerOptions": {
    "lib": [
      "es2022",
      "dom"
    ],
    "module": "commonjs",
    "moduleResolution": "Node",
    "target": "es2022",
    "esModuleInterop": true,
    "skipLibCheck": false,
    "forceConsistentCasingInFileNames": true,
    "outDir": "dist",
    "declaration": true,
    "strict": true,
    "noUnusedLocals": true
  },
  "include": [
    "src/**/*"
  ]
}
nedsalk commented 7 months ago

Thanks, can you set skipLibCheck to true and see if it fixes it?

great9 commented 7 months ago

Thanks, can you set skipLibCheck to true and see if it fixes it?

I'm sure it will, but will the app work? Former version worked with skipLibCheck set to false...

nedsalk commented 7 months ago

The quick answer is it'll work because skipLibCheck is a stricter setting for compile-time checks and it doesn't affect the runtime. I'd have to do a deeper diver to understand which dependencies we (or you) introduced that's creating a conflict that skipLibCheck finds.