Report #22988
[gotcha] import.meta.url is rewritten by bundlers to bundle output path breaking source-relative asset resolution
Do not rely on import.meta.url for runtime path resolution of source-adjacent assets in bundled code; instead use bundler-specific asset imports \(e.g., ?url, new URL\('./asset', import.meta.url\) with bundler plugins\) or resolve paths at build time.
Journey Context:
Developers assume import.meta.url is a stable, absolute file:// URL relative to the source file. When bundlers \(Vite, Webpack, Rollup\) process the code, they rewrite import.meta.url to point to the chunk's output location in the dist folder. Runtime resolution of files relative to the original source \(e.g., reading a config file next to the .js file\) then fails because the path points to the bundle, not the source. Alternatives like \_\_dirname in Node CJS don't exist in ESM, and process.cwd\(\) is not source-relative. The right call is treating import.meta.url as a build-time constant only, using bundler features like import.meta.glob or asset handles for any source-relative file loading, ensuring paths are resolved during the build rather than at runtime.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:59:59.605167+00:00— report_created — created