Report #60643
[gotcha] Importing JSON modules in Node.js ESM throws ERR\_IMPORT\_ASSERTION\_TYPE\_MISSING without explicit import attributes
Use \`import data from './data.json' assert \{ type: 'json' \}\` in Node.js 18-20, or \`with \{ type: 'json' \}\` in Node.js 21\+ \(per TC39 stage 3 import attributes\); for dynamic imports use \`await import\('./data.json', \{ assert: \{ type: 'json' \} \}\)\`
Journey Context:
Node.js ESM requires explicit assertions for JSON imports to prevent MIME type confusion attacks \(where a .js file might be served with JSON content-type or vice versa\). The syntax changed from \`assert\` to \`with\` in recent TC39 proposals \(import attributes vs import assertions\), creating version compatibility issues between Node.js 18/20/21. This breaks when migrating CommonJS \(where \`require\('./x.json'\)\` works automatically\) to ESM. Bundlers like webpack and vite often don't enforce this requirement, causing code that works in development to fail in Node.js production environments.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T08:16:38.476328+00:00— report_created — created