Exemplo
Import a CommonJS-only package from an ES module without the named-export or require-is-not-defined errors
sha256:e991b2b17774ff91d87fbe5ebfa2b3997a9f8b8c1fae7cb5d671573c6ebe68a9
CROSS_PASS
L4_CROSS_PASS
MIT-0
Caso
- Objetivo
- Import a CommonJS-only package from an ES module without the named-export or require-is-not-defined errors FIX
- Pacotes
- lodash 4.18.1
- Ambiente
- node 22
- Criado
- 2026-08-13T14:19:47Z
Contrato
- importing a named export from the CJS-only package throws SyntaxError: Named export 'chunk' not found ... is a CommonJS module
- calling require() in ES module scope throws ReferenceError: require is not defined in ES module scope
- the default-import interop pattern returns correct lodash results for chunk, groupBy and a deep merge that does not mutate its input
- createRequire(import.meta.url) supplies real require semantics: it requires a JSON subpath inside the dependency and resolves the package to a filesystem path
- import * as namespace leaves the CJS functions undefined on the namespace and reachable only through namespace.default
Arquivos
- csx.json
- package-lock.json
- package.json
- src/broken-named-import.mjs
- src/broken-require.mjs
- src/index.mjs
- test/contract.mjs
Seeder de origem
Recibos de verificação
- node 22 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · node-typescript@1 · 2026-08-13 · ed25519:a2ec939a4c60e243
- node 22 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · node-typescript@1 · 2026-08-13 · ed25519:a2ec939a4c60e243
- · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · node-typescript@1 · 2026-08-13 · ed25519:7da3f610facce8bf
- node 22 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · node-typescript@1 · 2026-08-13 · ed25519:a2ec939a4c60e243
- · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · node-typescript@1 · 2026-08-13 · ed25519:7da3f610facce8bf
- · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · node-typescript@1 · 2026-08-13 · ed25519:7da3f610facce8bf
- · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · node-typescript@1 · 2026-08-13 · ed25519:7da3f610facce8bf
- node 22 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · node-typescript@1 · 2026-08-13 · ed25519:a2ec939a4c60e243