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: Must use import to load ES Module for undici/lib/llhttp/llhttp.wasm #2062

Closed
jeromemacias opened this issue Apr 12, 2023 · 1 comment · Fixed by #2064
Closed

Error: Must use import to load ES Module for undici/lib/llhttp/llhttp.wasm #2062

jeromemacias opened this issue Apr 12, 2023 · 1 comment · Fixed by #2064
Labels
bug Something isn't working

Comments

@jeromemacias
Copy link

jeromemacias commented Apr 12, 2023

Bug Description

Error when loading undici into jest unit tests

Logs

Tests run using:
NODE_OPTIONS=--experimental-vm-modules npx jest --run-in-band --verbose --ci

Error log:

/home/runner/work/my-project/my-project/node_modules/jest-runtime/build/index.js:841
      const error = new Error(
                    ^

Error: Must use import to load ES Module: /home/runner/work/my-project/my-project/node_modules/undici/lib/llhttp/llhttp.wasm
    at Runtime.requireModule (/home/runner/work/my-project/my-project/node_modules/jest-runtime/build/index.js:841:21)
    at Runtime.requireModuleOrMock (/home/runner/work/my-project/my-project/node_modules/jest-runtime/build/index.js:1039:21)
    at lazyllhttp (/home/runner/work/my-project/my-project/node_modules/undici/lib/client.js:362:55)
    at Object.<anonymous> (/home/runner/work/my-project/my-project/node_modules/undici/lib/client.js:424:21)
    at Runtime._execModule (/home/runner/work/my-project/my-project/node_modules/jest-runtime/build/index.js:1429:24)
    at Runtime._loadModule (/home/runner/work/my-project/my-project/node_modules/jest-runtime/build/index.js:1013:12)
    at Runtime.requireModule (/home/runner/work/my-project/my-project/node_modules/jest-runtime/build/index.js:873:12)
    at Runtime.requireModuleOrMock (/home/runner/work/my-project/my-project/node_modules/jest-runtime/build/index.js:1039:21)
    at Object.<anonymous> (/home/runner/work/my-project/my-project/node_modules/undici/index.js:3:16)
    at Runtime._execModule (/home/runner/work/my-project/my-project/node_modules/jest-runtime/build/index.js:1429:24)
    at Runtime._loadModule (/home/runner/work/my-project/my-project/node_modules/jest-runtime/build/index.js:1013:12)
    at Runtime.requireModule (/home/runner/work/my-project/my-project/node_modules/jest-runtime/build/index.js:873:12)
    at Runtime.requireModuleOrMock (/home/runner/work/my-project/my-project/node_modules/jest-runtime/build/index.js:1039:21)
    at Runtime.loadCjsAsEsm (/home/runner/work/my-project/my-project/node_modules/jest-runtime/build/index.js:717:22)
    at Runtime.resolveModule (/home/runner/work/my-project/my-project/node_modules/jest-runtime/build/index.js:675:17)
    at ModuleWrap.<anonymous> (node:internal/vm/module:306:24) {
  code: 'ERR_REQUIRE_ESM'

Environment

NodeJS: 18.15.0
Jest: 29.5.0
ts-jest: 29.0.5
ts-node: 10.9.1
typescript: 4.9.5
undici: 5.21.2

Jest config:

export default {
  preset: 'ts-jest/presets/default-esm',
  moduleNameMapper: {
    '^(\\.{1,2}/.*)\\.js$': '$1'
  },
  extensionsToTreatAsEsm: ['.ts'],
  testEnvironment: 'node',
  roots: ['<rootDir>/src/']
}

TS config:

{
  "compilerOptions": {
    "lib": ["ESNext", "DOM"],
    "target": "ES2022",
    "strict": false,
    "module": "NodeNext",
    "moduleResolution": "nodenext",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "sourceMap": true,
    "declaration": true,
    "declarationMap": true, // enables importers to jump to source
    "removeComments": true
  },
  "include": ["src/**/*", "test/*"]
}

Additional context

Error appears on undici v5.16.0
Possibly comes from : d0a99c2

@jeromemacias jeromemacias added the bug Something isn't working label Apr 12, 2023
@KhafraDev
Copy link
Member

Does this fix your issues?

#1878 (comment)

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

Successfully merging a pull request may close this issue.

2 participants