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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting cjs error with "index.cjs not supported" when I run tests #1008

Open
DanielRuf opened this issue Mar 11, 2024 · 2 comments
Open

getting cjs error with "index.cjs not supported" when I run tests #1008

DanielRuf opened this issue Mar 11, 2024 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@DanielRuf
Copy link

DanielRuf commented Mar 11, 2024

馃挰 how to resolve the cjs error

When I run jest in my project, I get an error:

$ USE_MOCKS=true && jest --detectOpenHandles
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/druf/Schreibtisch/projects/project-name/01-Backend/node_modules/string-width/index.js from /home/druf/Schreibtisch/projects/project-name/01-Backend/node_modules/cliui/build/index.cjs not supported.
Instead change the require of index.js in /home/druf/Schreibtisch/projects/project-name/01-Backend/node_modules/cliui/build/index.cjs to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/home/druf/Schreibtisch/projects/project-name/01-Backend/node_modules/cliui/build/index.cjs:291:21)
    at Object.<anonymous> (/home/druf/Schreibtisch/projects/project-name/01-Backend/node_modules/yargs/build/index.cjs:1:60678)
    at Object.<anonymous> (/home/druf/Schreibtisch/projects/project-name/01-Backend/node_modules/yargs/index.cjs:5:30)
    at _yargs (/home/druf/Schreibtisch/projects/project-name/01-Backend/node_modules/jest-cli/build/run.js:30:39)
    at buildArgv (/home/druf/Schreibtisch/projects/project-name/01-Backend/node_modules/jest-cli/build/run.js:149:26)
    at Object.run (/home/druf/Schreibtisch/projects/project-name/01-Backend/node_modules/jest-cli/build/run.js:124:24)
    at Object.<anonymous> (/home/druf/Schreibtisch/projects/project-name/01-Backend/node_modules/jest-cli/bin/jest.js:16:17)
    at Object.<anonymous> (/home/druf/Schreibtisch/projects/project-name/01-Backend/node_modules/jest/bin/jest.js:12:3)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

yarn why string-width tells me, that it probably comes from @fastify/static. forceESM is not set by us. Not sure why this happens.

yarn why string-width  
yarn why v1.22.19
[1/4] Why do we have the module "string-width"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "string-width@5.1.2"
info Reasons this module exists
   - "@fastify#static#glob#jackspeak#@isaacs#cliui" depends on it
   - Hoisted from "@fastify#static#glob#jackspeak#@isaacs#cliui#string-width"
   - Hoisted from "@fastify#static#glob#jackspeak#@isaacs#cliui#wrap-ansi#string-width"
info Disk size without dependencies: "172KB"
info Disk size with unique dependencies: "308KB"
info Disk size with transitive dependencies: "328KB"
info Number of shared dependencies: 4
Done in 0.30s.

Your Environment

  • node version: 18.19.1
  • fastify version: 4.26.2
  • os: Linux
  • fastify-static version: 7.0.1
@DanielRuf DanielRuf added the help wanted Extra attention is needed label Mar 11, 2024
@mcollina
Copy link
Member

Thanks for reporting!

Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.

@DanielRuf
Copy link
Author

Thanks for your swift reply @mcollina. I will have to invest some time for that, since this is a project that was created by another company and we are currently just maintaining it (doing upgrades). So I will have to dive a bit deeper and check which test file causes this.

In general the whole setup is a bit more complex since it involves multiple plugins and a distributed file structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants