Closed ldiqual closed 2 weeks ago
Node.js v20.17.0 jiti: 2.0.0 moment-timezone: 0.5.45
import 'moment-timezone'
Run with:
JITI_DEBUG=1 node --import jiti/register test.ts
Jiti fails to import moment-timezone with error:
Error [ERR_REQUIRE_ESM]: require() of ES Module file:///path/to/node_modules/moment-timezone/data/packed/latest.json not supported.
No response
[jiti] [init] version: 2.0.0 module-cache: true fs-cache: true interop-defaults: false [jiti] [cache] [hit] ./scripts/test.ts ~> ./node_modules/.cache/jiti/scripts-test.903402b1.mjs [jiti] [init] version: 2.0.0 module-cache: true fs-cache: true interop-defaults: false [jiti] [native] [import] /path/to/node_modules/moment-timezone/index.js [jiti] [cache] [hit] /path/to/node_modules/moment-timezone/index.js ~> ./node_modules/.cache/jiti/moment-timezone-index.4501337a.mjs node:internal/modules/esm/loader:566 throw new ERR_REQUIRE_ESM(url, true); ^ Error [ERR_REQUIRE_ESM]: require() of ES Module file:///path/to/node_modules/moment-timezone/data/packed/latest.json not supported. at Object.<anonymous> (/path/to/node_modules/moment-timezone/index.js:2:16) { code: 'ERR_REQUIRE_ESM' } Node.js v20.17.0
Thanks for report. With 2.1 we enabled interopDefault by default (https://github.com/unjs/jiti/pull/310) which resolves this.
Added test https://github.com/unjs/jiti/commit/1d86ca3a68cb5af1563cc27d328c72ec0e5c22b5#diff-19e56682197c4354febf4c924009c8ddc2d2d1bc33f281d083b1f4ad8c1b3919R1
Environment
Node.js v20.17.0 jiti: 2.0.0 moment-timezone: 0.5.45
Reproduction
test.ts
Run with:
Describe the bug
Jiti fails to import moment-timezone with error:
Additional context
No response
Logs