Runtime transpiler cache causes unknown-extension ESM imports to use the TSX loader on a warm cache
bugneeds triage
### What version of Bun is running?
1.4.0-canary.1+8adb8de8b
### What platform is your computer?
Darwin 25.5.0 arm64 arm
### What steps can reproduce the bug?
An entry point eligible for Bun's runtime transpiler cache imports an SVG correctly on the first run, but the identical second run incorrectly parses the SVG as TSX.
The entry point must be larger than the cache's 4 KiB minimum. The imported asset itself can be tiny.
```sh
mkdir bun-runtime-cache-repro
cd bun-runtime-cache-repro
printf '<svg xmlns="http://www.w3.org/2000/svg"/>' > asset.svg
bun -e 'await Bun.write("run.ts", `import asset from "./asset.svg";\n/*${"x".repeat(5000)}*/\nconsole.log(asset);\n`)'
export BUN_RUNTIME_TRANSPILER_CACHE_PATH="$(mktemp -d)"
bun run run.ts
bun run run.ts
```
No plugin, mock, or test runner is involved. Setting `BUN_RUNTIME_TRANSPILER_CACHE_PATH=0` also makes repeated runs succeed.
### What is the expected behavior?
Both invocations should behave identically and print the absolute path to `asset.svg`, as specified by Bun's built-in `file` loader:
```text
/path/to/bun-runtime-cache-repro/asset.svg
```
### What do you see instead?
The first invocation succeeds and prints the SVG path.
The identical second invocation, using the now-warm runtime transpiler cache, fails:
```text
SyntaxError: Missing 'default' export in module '/path/to/bun-runtime-cache-repro/asset.svg'.
```
Bun appears to parse the SVG as TSX on the cache-hit run instead of applying the built-in file loader.
### Additional information
This reproduces deterministically on:
- `1.4.0-canary.1+8adb8de8b`
- `1.4.0-canary.1+dc5748f36`
- `1.4.0-canary.1+aca54d5c2`
- Darwin arm64 and Linux x64
It was originally observed in a real `bun test` CI suite. With a fresh explicit cache, the test file passed all 26 tests on the first invocation. The identical second invocation failed while importing an SVG with the same missing-default-export error.
The likely cause is that the runtime-transpiler-cache hit returns before the main module sets `has_loaded`. Subsequent unknown-extension ESM imports therefore take the entry-point fallback and select the TSX loader instead of the `file` loader.
关闭于 27 天前 2 条评论