Open
Description
Describe the bug
When importing a .js
file that in turn imports a .json
file with the ?url
suffix , Vite resolves the asset URL differently depending on whether the import is via a bare package specifier or a relative path into node_modules
.
Let's say I have a dependency in node_modules containing the file
node_modules/subpackage/a.js:
import a from "./a.json?url";
export default a;
and then i import it like
import a from "subpackage/a.js";
a
will be the inline json object.
But if I import it like
import a from "./node_modules/subpackage/a.js";
a
will be a string path, as expected.
I made a minimal repro here: https://github.com/tldraw/vite-6-import-failure-repro/tree/minimal-repro (note the branch name)
Solves tldraw/tldraw#6313
Reproduction
https://github.com/tldraw/vite-6-import-failure-repro/tree/minimal-repro
Steps to reproduce
Run git checkout minimal-repro && npm install && npm run dev
System Info
System:
OS: macOS 15.4.1
CPU: (10) arm64 Apple M1 Pro
Memory: 111.73 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.16.0 - ~/.nvm/versions/node/v22.16.0/bin/node
Yarn: 3.5.0 - ~/.nvm/versions/node/v22.16.0/bin/yarn
npm: 10.9.2 - ~/.nvm/versions/node/v22.16.0/bin/npm
pnpm: 9.15.4 - ~/.nvm/versions/node/v22.16.0/bin/pnpm
bun: 1.2.7 - /opt/homebrew/bin/bun
Browsers:
Chrome: 137.0.7151.120
Safari: 18.4
npmPackages:
vite: ^6.3.5 => 6.3.5
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.