Report #70141
[gotcha] Importing JSON modules fails with TypeError or returns incorrect module namespace without import assertions \(now attributes\)
Always use \`with \{ type: 'json' \}\` \(or legacy \`assert \{ type: 'json' \}\`\) when importing JSON files as modules, and ensure your build tool/target environment supports import attributes.
Journey Context:
TC39 Import Assertions proposal \(now Import Attributes, Stage 4\) changed from \`assert\` to \`with\` keyword. The footgun is that without this attribute, the browser/node may treat the JSON as JS and fail to parse, or in some loader configurations, silently return a different object. Additionally, the syntax changed recently \(assert -> with\), causing version fragmentation. Pattern: Use a try-catch wrapper that falls back to fetch \+ JSON.parse for environments lacking attribute support, or use ?raw imports in Vite/webpack instead of native JSON modules to avoid the compatibility matrix entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:19:04.352945+00:00— report_created — created