mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 03:18:53 +00:00
Extends the fix to handle runtime dynamic imports with import attributes.
Previously, dynamic imports like:
await import("./file.json")
await import("./file.json", { with: { type: "text" } })
would return the same cached module, ignoring the type attribute.
Solution:
Uses JSC's existing query string mechanism to differentiate modules:
1. In moduleLoaderImportModule: Extract the type attribute from import
parameters and append it to the resolved identifier as a query string
(e.g., "/path/file.json" becomes "/path/file.json?type=text")
2. In moduleLoaderFetch: Strip the query string before loading the actual
file, so the filesystem path is correct
This approach:
- Leverages existing infrastructure (query strings already supported)
- Clean and non-invasive (no string hacks in paths)
- Works with JSC's built-in module caching
Result: Dynamic imports with different type attributes now correctly return
different module instances (e.g., object vs string for JSON).
Note: Static imports (import x from "file" with {type: "..."}) still don't
work at runtime - this is a JSC limitation where moduleLoaderResolve doesn't
receive import attributes at parse time. The bundler handles static imports
correctly.