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

Importing moment-timezone from ESM context fails with require() of ES Module latest.json is not supported #314

Closed
ldiqual opened this issue Oct 1, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ldiqual
Copy link

ldiqual commented Oct 1, 2024

Environment

Node.js v20.17.0
jiti: 2.0.0
moment-timezone: 0.5.45

Reproduction

test.ts

import 'moment-timezone'

Run with:

JITI_DEBUG=1 node --import jiti/register test.ts

Describe the bug

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.

Additional context

No response

Logs

[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
@ldiqual ldiqual added the bug Something isn't working label Oct 1, 2024
@pi0
Copy link
Member

pi0 commented Oct 2, 2024

Thanks for report. With 2.1 we enabled interopDefault by default (#310) which resolves this.

Added test 1d86ca3#diff-19e56682197c4354febf4c924009c8ddc2d2d1bc33f281d083b1f4ad8c1b3919R1

@pi0 pi0 closed this as completed Oct 2, 2024
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

No branches or pull requests

2 participants