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

[Bug]: CommonJS / ESM modules issue #14881

Closed
Netail opened this issue Feb 5, 2024 · 3 comments
Closed

[Bug]: CommonJS / ESM modules issue #14881

Netail opened this issue Feb 5, 2024 · 3 comments

Comments

@Netail
Copy link

Netail commented Feb 5, 2024

Version

29.7.0

Steps to reproduce

  1. Dev dependencies:
    "@testing-library/jest-dom": "^6.4.1",
    "@testing-library/react": "^14.2.1",
    "jest": "^29.7.0",
    "jest-environment-jsdom": "^29.7.0",

  2. Run jest --passWithNoTests

Expected behavior

Runs actual tests

Actual behavior

Throw the following exception:

Error [ERR_REQUIRE_ESM]: require() of ES Module <dir>/node_modules/string-width/index.js from <dir>/node_modules/cliui/build/index.cjs not supported.
Instead change the require of index.js in <dir>/node_modules/cliui/build/index.cjs to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (<dir>/node_modules/cliui/build/index.cjs:291:21)
    at Object.<anonymous> (<dir>/node_modules/yargs/build/index.cjs:1:60678)
    at Object.<anonymous> (<dir>/node_modules/yargs/index.cjs:5:30)
    at _yargs (<dir>/node_modules/jest-cli/build/run.js:30:39)
    at buildArgv (<dir>/node_modules/jest-cli/build/run.js:149:26)
    at Object.run (<dir>/node_modules/jest-cli/build/run.js:124:24)
    at Object.<anonymous> (<dir>/node_modules/jest-cli/bin/jest.js:16:17)
    at Object.<anonymous> (<dir>/node_modules/jest/bin/jest.js:12:3)

Additional context

Might be related as they face the same issue with the dependency string-width
isaacs/jackspeak#5
https://stackoverflow.com/questions/77186044/error-require-of-es-module-when-trying-to-run-a-node-container

TSConfig;

{
    "compilerOptions": {
        "composite": false,
        "declaration": true,
        "declarationMap": true,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "inlineSources": false,
        "isolatedModules": true,
        "moduleResolution": "bundler",
        "noUnusedLocals": false,
        "noUnusedParameters": false,
        "preserveWatchOutput": true,
        "resolveJsonModule": true,
        "skipLibCheck": true,
        "strict": true,
        "strictNullChecks": true,
        "target": "es2017",
        "lib": [
            "dom",
            "dom.iterable",
            "esnext"
        ],
        "allowJs": true,
        "noEmit": true,
        "incremental": true,
        "module": "esnext",
        "jsx": "preserve",
        "plugins": [
            {
                "name": "next"
            }
        ],
        "baseUrl": "./",
        "paths": {
            "@*": [
                "./*"
            ]
        }
    },
    "include": [
        "next-env.d.ts",
        "**/*.ts",
        "**/*.tsx",
        ".next/types/**/*.ts"
    ],
    "exclude": [
        "node_modules"
    ]
}

Environment

System:
    OS: macOS 14.2.1
    CPU: (10) arm64 Apple M1 Max
  Binaries:
    Node: 20.8.1 - ~/.nvm/versions/node/v20.8.1/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v20.8.1/bin/yarn
    npm: 10.1.0 - ~/.nvm/versions/node/v20.8.1/bin/npm
    pnpm: 8.9.0 - ~/.nvm/versions/node/v20.8.1/bin/pnpm
@Netail Netail changed the title [Bug]: [Bug]: CommonJS / ESM modules issue Feb 5, 2024
@SimenB
Copy link
Member

SimenB commented Feb 5, 2024

I think this is a bug with yarn v1 - at least that was the issue at work. Upgrading to yarn v3 or v4 fixed it.

Either way, not a bug in Jest - fix would have to be further upstream (e.g. cliui)

@Netail
Copy link
Author

Netail commented Mar 6, 2024

Seems to be related to; yargs/cliui#138

Copy link

github-actions bot commented Apr 7, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 7, 2024
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

2 participants