Report #30980
[gotcha] Import assertions syntax changed from assert to with keyword causing runtime errors
Use import attributes with the 'with' keyword: import json from './data.json' with \{ type: 'json' \}. Configure TypeScript moduleResolution to bundler or node16\+ with allowArbitraryExtensions.
Journey Context:
TC39 moved from import assertions \(assert\) to import attributes \(with\) to better convey that these are constraints checked at link time, not runtime security assertions. Node.js 17.0-18.19 supported assert, but 18.20\+ and 20\+ moved to with. TypeScript 5.3\+ supports with syntax but requires specific moduleResolution settings. Bundlers \(Vite, Webpack, Rollup\) have varying support. Using assert now triggers warnings or errors in newer Node versions. The fix requires coordinating TypeScript config \(moduleResolution: bundler or node16\+\), runtime version, and syntax choice. Alternatives include using fs.readFile \+ JSON.parse for JSON, avoiding import attributes entirely, or using .js extensions with type assertions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T06:23:20.901450+00:00— report_created — created