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 /home/runner/work/isaacscript/isaacscript/node_modules/wrap-ansi/index.js from /home/runner/work/isaacscript/isaacscript/node_modules/nx/node_modules/yargs/node_modules/cliui/build/index.cjs not supported. #17229

Closed
2 of 4 tasks
Zamiell opened this issue May 25, 2023 · 9 comments

Comments

@Zamiell
Copy link
Contributor

Zamiell commented May 25, 2023

Current Behavior

Nx crashes with an error.

Expected Behavior

Nx should run without an error.

Steps to Reproduce

  1. git clone git@github.com:IsaacScript/isaacscript.git
  2. cd isaacscript
  3. git checkout a2ab4fdc399d00931561557e806bdee2f7ebcd74
  4. yarn
  5. npx nx report

You will get the following error:

+ npx nx run-many --target=build --all
/home/runner/work/isaacscript/isaacscript/node_modules/nx/node_modules/yargs/node_modules/cliui/build/index.cjs:293
const wrap = require('wrap-ansi');
             ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/runner/work/isaacscript/isaacscript/node_modules/wrap-ansi/index.js from /home/runner/work/isaacscript/isaacscript/node_modules/nx/node_modules/yargs/node_modules/cliui/build/index.cjs not supported.
Instead change the require of index.js in /home/runner/work/isaacscript/isaacscript/node_modules/nx/node_modules/yargs/node_modules/cliui/build/index.cjs to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/home/runner/work/isaacscript/isaacscript/node_modules/nx/node_modules/yargs/node_modules/cliui/build/index.cjs:293:[14](https://github.com/IsaacScript/isaacscript/actions/runs/5084290118/jobs/9136389446#step:6:15))
    at Object.<anonymous> (/home/runner/work/isaacscript/isaacscript/node_modules/nx/node_modules/yargs/build/index.cjs:1:60678)
    at Object.<anonymous> (/home/runner/work/isaacscript/isaacscript/node_modules/nx/node_modules/yargs/index.cjs:5:30)
    at Object.<anonymous> (/home/runner/work/isaacscript/isaacscript/node_modules/nx/src/command-line/nx-commands.js:5:[15](https://github.com/IsaacScript/isaacscript/actions/runs/5084290118/jobs/9136389446#step:6:16))
    at Object.<anonymous> (/home/runner/work/isaacscript/isaacscript/node_modules/nx/bin/init-local.js:7:23)
    at Object.<anonymous> (/home/runner/work/isaacscript/isaacscript/node_modules/nx/bin/nx.js:6:22) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v18.[16](https://github.com/IsaacScript/isaacscript/actions/runs/5084290118/jobs/9136389446#step:6:17).0
Error: Process completed with exit code 1.

Nx Report

I can't run nx report, I get the error listed above.

Failure Logs

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

You can see the error in the following GitHub Action run:
https://github.com/IsaacScript/isaacscript/actions/runs/5084290118/jobs/9136389446

The error seems to be because nx uses cliui, which tries to import wrap-ansi. wrap-ansi is supposed to be a CommonJS module, but is instead an ES module, causing the error.

Thus, I believe that the issue will occur with any brand new installations of nx.

@AgentEnder
Copy link
Member

This error doesn't really make sense, cliui does depend on wrap-ansi, but at v7, which is still CJS. v8 of wrap-ansi has been around for a decent chunk of time now, and I've not seen this reported before. Can you try regenerating your lockfile? I'm wondering if something went wrong when installing packages.

@AgentEnder AgentEnder added the scope: misc Misc issues label May 26, 2023
@AgentEnder AgentEnder self-assigned this May 26, 2023
@Zamiell
Copy link
Contributor Author

Zamiell commented May 26, 2023

Yes, I've tried nuking node_modules directory + yarn.lock file multiple times, and the error persists. You can follow the reproduction steps that I've listed above in the OP to confirm. (Feel free to delete the yarn.lock file after cloning the repo.)

@AgentEnder
Copy link
Member

After regenerating the lockfile locally, it seemed to work for me. You can see the changes here: IsaacScript/isaacscript#57

@AgentEnder
Copy link
Member

To be clear, I was able to repro before regenerating the lockfile. I'm not sure how it was deduping v8 of wrap-ansi, that was invalid and npm ls highlighted it as such.

It kind of seems like a package manager bug, but a nasty one that I'm not sure what would have caused.

@Zamiell
Copy link
Contributor Author

Zamiell commented May 26, 2023

After merging your PR, we can still see the exact same error in CI: https://github.com/IsaacScript/isaacscript/actions/runs/5094206401/jobs/9157731090

@AgentEnder
Copy link
Member

Yeah, I saw that but can't really speak to it...

If you pull down the commit SHA referenced in this issue, and run install its broken.
If you run rm -rf yarn.lock node_modules, and then run yarn it works as it should.
If you run rm -rf node_modules, and then run yarn --frozen-lockfile its broken again. This is essentially what CI is doing.

Like I said, this seems like a really nasty issue with the package manager, its not something thats coming from Nx's side of things. This pattern reproduced for your repo on your CI, my machine, and a colleague's, but I don't think there is much more assistance we can provide. I'd recommend opening an issue on yarn's repo, and perhaps investigate updating some of your other packages.

@Zamiell
Copy link
Contributor Author

Zamiell commented May 26, 2023

Thanks for taking the time to look into it Ender.

For others reading this thread, I was able to solve the problem by upgrading from Yarn 1 to Yarn 3. (I'm not using plug-n-play, i.e. I'm still using the node_modules directory.)

@doughlass
Copy link

Thanks for taking the time to look into it Ender.

For others reading this thread, I was able to solve the problem by upgrading from Yarn 1 to Yarn 3. (I'm not using plug-n-play, i.e. I'm still using the node_modules directory.)

I was on Node 20 but rolled back to Node 18, still using Yarn 1 and seems to work.

I also have nvm installed and use this, I noticed even though I switched to Node 18 I notice nx was still trying to use Node 20.

Deleted all node_modules and yarn.lock and reopened the terminal and yarn to reinstall and then nx worked.

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants