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

Error [ERR_REQUIRE_ESM]: require() of ES Module #725

Open
phDooY opened this issue Jun 17, 2024 · 11 comments
Open

Error [ERR_REQUIRE_ESM]: require() of ES Module #725

phDooY opened this issue Jun 17, 2024 · 11 comments
Labels
bug Something isn't working

Comments

@phDooY
Copy link

phDooY commented Jun 17, 2024

[REQUIRED] Environment

  • Browser version: not in browser
  • AA SDK version: 3.18.2
  • Package: aa-alchemy

[REQUIRED] Describe the problem

Before and including version 3.9.0 didn't have this issue. Trying to upgrade for several weeks already, resulting in following issue:

: Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/@wagmi/core/dist/esm/exports/index.js from /node_modules/@alchemy/aa-alchemy/dist/cjs/config/utils/cookies.js not supported.
: Instead change the require of index.js in /node_modules/@alchemy/aa-alchemy/dist/cjs/config/utils/cookies.js to a dynamic import() which is available in all CommonJS modules.
:     at Hook.Module.require (/node_modules/dd-trace/packages/dd-trace/src/ritm.js:85:33)
:     at Object.<anonymous> (/node_modules/@alchemy/aa-alchemy/dist/cjs/config/utils/cookies.js:7:16) {
:   code: 'ERR_REQUIRE_ESM'
: }
: 
: Node.js v21.7.1

How to reproduce:

"compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "ES2022",
    "sourceMap": true,
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,
    "allowJs": true,
    "paths": {},
    "baseUrl": "./"
  }

Relevant code or sample repro:

@phDooY phDooY added the bug Something isn't working label Jun 17, 2024
@neerajnerlekar
Copy link

I am getting this same error too. Could you let me know if you were able to resolve this?

@moldy530
Copy link
Collaborator

moldy530 commented Jul 8, 2024

@neerajnerlekar are you still seeing this on the latest version? It should have been fixed. If not can you send me an updated stacktrace?

The one in the report here seems to be related to something we fixed, so there might be something else that's not CJS compatible

@HarukiKondo
Copy link

I am getting this same error too.

@moldy530
Copy link
Collaborator

@HarukiKondo can you post a stack trace of your error?

@HarukiKondo
Copy link

@moldy530 Ok. Here is a stack trace in my case

node_modules/ts-node/dist/index.js:851
            return old(m, filename);
                   ^
Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/@wagmi/core/dist/esm/exports/index.js from node_modules/@alchemy/aa-alchemy/dist/cjs/config/utils/cookies.js not supported.
Instead change the require of index.js in node_modules/@alchemy/aa-alchemy/dist/cjs/config/utils/cookies.js to a dynamic import() which is available in all CommonJS modules.
    at require.extensions.<computed> [as .js] (node_modules/ts-node/dist/index.js:851:20)
    at Object.<anonymous> (node_modules/@alchemy/aa-alchemy/dist/cjs/config/utils/cookies.js:7:16)
    at require.extensions.<computed> [as .js] (node_modules/ts-node/dist/index.js:851:20) {
  code: 'ERR_REQUIRE_ESM'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 1
Command: /home/ubuntu/.nvm/versions/node/v20.13.1/bin/node
Arguments: /home/ubuntu/.nvm/versions/node/v20.13.1/lib/node_modules/yarn/lib/cli.js aa:test
Directory: /home/ubuntu/environment/NFTSmartKeyPoc/packages/cdk-nft-sample
Output:

info Visit https://yarnpkg.com/en/docs/cli/workspace for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@HarukiKondo
Copy link

I executed on AWS Cloud9.

"dependencies": {
    "@alchemy/aa-accounts": "^3.18.2",
    "@alchemy/aa-alchemy": "3.16.0",
    "@alchemy/aa-core": "3.16.0",
}

@moldy530
Copy link
Collaborator

Ah yeah, try upgrading all the packages to 3.18.2 and see if that resolves it

@HarukiKondo
Copy link

@moldy530 Thank you! I will try it!

@HarukiKondo
Copy link

@moldy530 I upgraded all the packages to 3.18.2. But I am getting this same error too.

@neerajnerlekar
Copy link

I updated it to 3.18.2 and I am still getting the same error in stack trace.

I even cloned Dan's github repo associated with the video, and it still gives the same error

Here is my package.json

{
  "name": "aa-sdk-demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/node": "^20.12.3",
    "ts-node": "^10.9.2",
    "typescript": "^5.4.3"
  },
  "dependencies": {
    "@alchemy/aa-alchemy": "^3.18.2",
    "@alchemy/aa-core": "^3.18.2",
    "dotenv": "^16.4.5",
    "viem": "^2.9.15"
  }
}

Here is the stack trace of the error.

node_modules/ts-node/dist/index.js:851
            return old(m, filename);
                   ^
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/aa-sdk-userops/node_modules/@wagmi/core/dist/esm/exports/index.js from /home/aa-sdk-userops/node_modules/@alchemy/aa-alchemy/dist/cjs/config/utils/cookies.js not supported.
Instead change the require of index.js in /home/aa-sdk-userops/node_modules/@alchemy/aa-alchemy/dist/cjs/config/utils/cookies.js to a dynamic import() which is available in all CommonJS modules.
    at require.extensions.<computed> [as .js] (/home/aa-sdk-userops/node_modules/ts-node/dist/index.js:851:20)
    at Object.<anonymous> (/home/aa-sdk-userops/node_modules/@alchemy/aa-alchemy/dist/cjs/config/utils/cookies.js:7:16)
    at require.extensions.<computed> [as .js] (/home/aa-sdk-userops/node_modules/ts-node/dist/index.js:851:20) {
  code: 'ERR_REQUIRE_ESM'
}

@moldy530
Copy link
Collaborator

ah the issue is the version of wagmi :/ https://wagmi.sh/react/guides/migrate-from-v1-to-v2#dropped-commonjs-support

wagmi in v2 no longer supports CJS. Most likely you'll have to migrate over to using ESM instead of CJS. We'll take a look at the example repo as well and double check that it's setup for ESM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants