Brushfam / typechain-polkadot

Tool that generates typescript bindings for ink! smart contracts
https://brushfam.io/
MIT License
17 stars 19 forks source link

SyntaxError: Cannot use import statement outside a module #115

Open 0xHendrix opened 11 months ago

0xHendrix commented 11 months ago

Using @727-ventures/typechain-polkadot": "1.1.0" and running typechain-polkadot --in src/abi --out src/types I get the following error in a Monorepo setup using PNPM:

import {Abi} from "@polkadot/api-contract";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1178:20)
    at Module._compile (node:internal/modules/cjs/loader:1220:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Object.require.extensions.<computed> [as .ts]

tsconfig.json:

{
  "compilerOptions": {
    "baseUrl": ".",
    "outDir": "dist",
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "lib": ["esnext"],
    "pretty": true,
    "allowJs": true,
    "skipLibCheck": true,
    "alwaysStrict": true,
    "strict": true,
    "strictNullChecks": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "incremental": true,
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "isolatedModules": true,
    "jsx": "preserve"
  },
  "exclude": ["**/node_modules", "**/dist"]
}

package.json:

{
  "name": "@project/contracts",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "module": "./dist/index.js",
  "types": "./dist/index.d.ts",
  "exports": {
    ".": {
      "import": "./dist/index.js",
      "types": "./dist/index.d.ts"
    }
  },
  "scripts": {
    "build": "pnpm run generate:types",
    "lint": "eslint --fix",
    "format": "prettier --write src/*",
    "generate:types": "polkadot-types-from-chain --endpoint wss://ws.test.azero.dev --output src/types",
    "generate:client": "typechain-polkadot --in src/abi --out src/client"
  },
  "dependencies": {
    "@polkadot/api": "10.9.1"
  },
  "devDependencies": {
    "@727-ventures/typechain-polkadot": "1.1.0",
    "@polkadot/typegen": "10.9.1",
    "ts-node": "10.9.1",
    "typescript": "5.1.6"
  }
}

Does this package support an ESM based repo?

wottpal commented 3 months ago

Same issue