ERR_IMPORT_ASSERTION_TYPE_MISSING
node
esm
ai_generated
true
TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module needs an import attribute of type 'json'
ID: node/err-import-assertion-type-missing
95%Fix Rate
96%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 20 | active | — | — | — |
Root Cause
Importing a JSON module without the required import assertion in ESM mode.
genericWorkarounds
-
96% success Add import assertion: import data from './data.json' with { type: 'json' }
Node 20+ uses 'with' syntax; older versions use 'assert'
-
88% success Use fs.readFileSync + JSON.parse as an alternative
const data = JSON.parse(fs.readFileSync('./data.json', 'utf-8'))
Dead Ends
Common approaches that don't work:
-
Converting the JSON file to a .js module that exports the data
60% fail
Extra build step; breaks co-located config patterns
-
Switching back to CommonJS to use require()
70% fail
Loses ESM benefits for the whole project
Error Chain
Frequently confused with: