-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vite should stop appending ?import
for data URLs
#2658
Comments
thought (dx): Magic comments are having the problem that they get removed if using Could it be possible to wrap the e.g.: import { viteImport } from 'vite'
const blob = new Blob([/* */], { type: '...' })
const url = URL.createObjectURL(blob)
;(async () => {
await viteImport(url, { noImport: true }) // <== Vite injects `?import` query here.
})() export async function viteImport(url, options) {
// do things with url and options
const imported = await import(url)
// do things with imported and options
return imported
} |
Or, we can add a detection that checks if it starts with |
@Shinigami92 That solution (adding I'd like to submit a PR to add a detection that checks if URL starts with |
Would you create a minimal repro? There may be a bug here. The use of query strings is working well so far, and it is better aligned with import assertions. Other tools like WMR are considering to move away from prefixes. |
Minimal reproduction repository: https://github.com/rosaric/vite-bug-repro . |
@g-plane Totally with you! That was just a proposal for an alternative for the |
I don't mind magic comments, because they're trivial and don't affect my code directly, but using |
@g-plane But did you know that when using |
Yes, and my suggestion is to skip adding queries for |
Can I attempt to open a PR that adds a processing for URLs start with |
@g-plane You are always welcome to open any PR 😁 |
Describe the bug
Vite injects
?import
query to data URL in dynamicimport
calls, which should be unexpected.Reproduction
I hope if we add
@vite-ignore
magic comment, Vite won't inject?import
query, otherwise it will break the URL and cause failing to load such resources.The code of Vite below will mark "needs inject query": https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/importAnalysis.ts#L412
Then, Vite will inject at runtime: https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/importAnalysis.ts#L413
I hope we can add a detection:
Edit: My another solution is to skip adding queries for URLs which start with
blob:
anddata:
at both compile-time and runtime.System Info
Output of
npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:Used package manager: npm
Logs
Before submitting the issue, please make sure you do the following
The text was updated successfully, but these errors were encountered: