Report #82070
[gotcha] Import assertions \(assert\) fail in newer Node/TS, import attributes \(with\) fail in older ones
Use 'with' syntax for Node.js 20.10\+ and TypeScript 5.3\+. For older Node/TS, use 'assert'. If targeting mixed environments, use dynamic import\(\) with feature detection, or ensure build tools \(esbuild/vite\) handle the transformation uniformly.
Journey Context:
Import assertions were the original proposal \(assert \{ type: 'json' \}\), but TC39 moved to 'Import Attributes' using the 'with' keyword for better semantics \(attributes are applied during loading, not just asserted\). Node.js implemented assertions in v17.5, then switched to 'with' in v20.10 \(experimental\) and v21 stable. TypeScript 5.3 added 'with' support. Using the wrong syntax causes ERR\_IMPORT\_ASSERTION\_TYPE\_FAILED or parse errors. Build tools like esbuild/vite may transform one to the other, but tsc's moduleResolution: 'bundler' vs 'nodeNext' changes behavior. The safest path is aligning your Node major version with your TS version and using 'with' for modern stacks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T20:21:06.417940+00:00— report_created — created