-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Module resolution: Regression in JSON import using Node16 resolution #60589
Comments
Concise repro: // "module": "node16", "resolveJsonModule": true, in a *.mts file (does not apply to cjs output)
// TS error: Importing a JSON file into an ECMAScript module requires a 'type: "json"' import attribute when 'module' is set to 'Node16'.ts(1543)
import something1 from './someThing.json';
// TS error: Import attributes are only supported when the '--module' option is set to 'esnext', 'nodenext', or 'preserve'.ts(2823)
import something2 from './someThing.json' with { type: "json" }; (related, #60598) |
The issue is pretty poorly formatted, so to restate, the problem is that we require an import attribute for JSON in Node16 resolution, but import attributes are not allowed in Node16 resolution? |
That seems to be what's happening on our side, yes. |
I am seeing the same thing, and even if I bump the module to
|
Demo Repo
canvasxyz/canvas#405
Which of the following problems are you reporting?
Something else more complicated which I'll explain in more detail
Demonstrate the defect described above with a code sample.
import * as pkg from "../package.json"
Run
tsc --showConfig
and paste its output hereRun
tsc --traceResolution
and paste its output herePaste the
package.json
of the importing module, if it existsPaste the
package.json
of the target module, if it existsn/a
Any other comments can go here
A recent change that landed around 5.7.0 seems to break Node16 imports of .json files, because a
type: json
import attributed is required but also not allowed to be used: canvasxyz/canvas#404It might be related to this issue: #59684
Which was addressed in this PR: #60019
It seems to produce new errors in these automated builds: https://github.com/search?q=repo%3Amicrosoft%2FTypeScript+%22named+imports+are+not+allowed%22&type=issues
The text was updated successfully, but these errors were encountered: