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

[v57.0.0] Json import warning on Node 18.20 #2561

Open
kuoruan opened this issue Feb 18, 2025 · 3 comments
Open

[v57.0.0] Json import warning on Node 18.20 #2561

kuoruan opened this issue Feb 18, 2025 · 3 comments
Labels

Comments

@kuoruan
Copy link

kuoruan commented Feb 18, 2025

Warnings showing after upgrade to v57.0.0

NODE_OPTIONS='--trace-warnings' eslint .

(node:159194) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
    at emitExperimentalWarning (node:internal/util:274:11)
    at ModuleLoader.jsonStrategy (node:internal/modules/esm/translators:308:3)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:299:14)

Caused by:

import packageJson from './package.json' with {type: 'json'};

Can we use this?

import { createRequire } from "module";
const packageJson = createRequire(import.meta.url)("./package.json");
@kuoruan kuoruan added the bug label Feb 18, 2025
@RobinTail
Copy link

It also causes fatal error in Node 20.9.0.

Oops! Something went wrong! :(

ESLint: 9.20.1

SyntaxError: Unexpected token 'with'
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:118:18)
    at callTranslator (node:internal/modules/esm/loader:273:14)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:278:30)
error Command failed with exit code 2.

@RobinTail
Copy link

I think it was assert in some Node versions, but then changed to with.
Perhaps it should be transformed somehow, or it should be a dynamic import, IDK.
Or engines should be corrected.

@RobinTail
Copy link

RobinTail commented Feb 18, 2025

The same syntax is present in builtin-modules v4 that v57 uses, so fixing in one place won't be enough

import builtinModules from './builtin-modules.json' with {type: 'json'};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants