patternjavascriptCriticalCanonical
ERR_IMPORT_ASSERTION_TYPE_MISSING for import of json file
Viewed 0 times
forerr_import_assertion_type_missingfilejsonimport
Problem
This code was working fine.
I don't know if it's because I upgraded to Node 17 or what, but now I get
In my
Here's how I start
I don't know if it's because I upgraded to Node 17 or what, but now I get
TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]:
Module "file:///Users/xxxxx/code/projects/xxxxx/dist/server/data/countries.json"
needs an import assertion of type "json"In my
api.ts I have:import countryTable from './data/countries.json';Here's how I start
api.ts which is used by server.ts:NODE_ENV=production node --optimize_for_size --trace-warnings --experimental-json-modules --no-warnings server/server.jsSolution
Update
According to the proposal, the new keyword is
Old Answer
You will need to use:
https://github.com/tc39/proposal-import-assertions
According to the proposal, the new keyword is
with instead of assert; but assert is supposed to stay for compatibility reasons. The new code would look as follows:import countryTable from "./data/countries.json" with { type: "json" };
Old Answer
You will need to use:
import countryTable from "./data/countries.json" assert { type: "json" };
https://github.com/tc39/proposal-import-assertions
Context
Stack Overflow Q#70106880, score: 436
Revisions (0)
No revisions yet.