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

Compilation error v5.3.2 MODULE_NOT_FOUND and ERR_REQUIRE_ESM #556

Open
daochild opened this issue Sep 10, 2024 · 1 comment
Open

Compilation error v5.3.2 MODULE_NOT_FOUND and ERR_REQUIRE_ESM #556

daochild opened this issue Sep 10, 2024 · 1 comment

Comments

@daochild
Copy link

daochild commented Sep 10, 2024

  1. After install tronweb dependancy missing

Error: Cannot find module '@noble/secp256k1'
Require stack: C:\Users\user\Desktop\check_typescript_export\node_modules\tronweb\dist\TronWeb.node.js
code: 'MODULE_NOT_FOUND'

  1. If try to install missing package compilation ok, but execution of file is

C:\Users\user\Desktop\check_typescript_export\node_modules\tronweb\dist\TronWeb.node.js:315
undefined

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\user\Desktop\check_typescript_export\node_modules@noble\secp256k1\index.js from C:\Users\user\Desktop\check_typescript_export\node_modules\tronweb\dist\TronWeb.node.js not supported.
Instead change the require of index.js in C:\Users\user\Desktop\check_typescript_export\node_modules\tronweb\dist\TronWeb.node.js to a dynamic import() which is available in all CommonJS modules.

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "NodeNext",     
    "moduleResolution": "NodeNext",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "resolveJsonModule": true,
    "types": ["node"],
    "lib": ["es2020", "dom"],
    "rootDirs": ["src"],
    "outDir": "dist",
    "declaration": true,
    "declarationMap": true,
    "typeRoots": ["./node_modules/@types", "./src/**/*"],
    "noImplicitAny": false
  },
  "ts-node": {
    "esm": true
  }
}

package.json

  "devDependencies": {
    "@daochild/tronweb-typescript": "^1.2.105",
    "@noble/secp256k1": "^2.1.0",
    "@types/node": "^22.5.4",
    "ts-node": "^10.9.2",
    "typescript": "^5.5.4"
  },
  "dependencies": {
    "tronweb": "^5.3.2"
  },
$ node --version
v22.6.0
$ npm --version
10.8.3
OS: W10

P.S. if compile code with commonjs ERR_REQUIRE_ESM still presents, node v20 same errors

@Satan-web3
Copy link
Contributor

See here for solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants