-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Windows: Import normalization can incorrectly resolve as both in and out of root #2422
Comments
Yes, I approved it, after updating svelte@next to newer version, it falls. |
I've located the specific file and line which causes the stripping of vite/packages/vite/src/node/utils.ts Lines 121 to 126 in 76f3535
Line 122's usage of the deprecated {
protocol: 'c:',
slashes: null,
auth: null,
host: '',
port: null,
hostname: '',
hash: null,
search: null,
query: null,
pathname: '/Users/GrygrFlzr/Documents/projects/vite-windows-imports/node_modules/.pnpm/svelte@3.35.0/node_modules/svelte/internal/index.mjs',
path: '/Users/GrygrFlzr/Documents/projects/vite-windows-imports/node_modules/.pnpm/svelte@3.35.0/node_modules/svelte/internal/index.mjs',
href: 'c:/Users/GrygrFlzr/Documents/projects/vite-windows-imports/node_modules/.pnpm/svelte@3.35.0/node_modules/svelte/internal/index.mjs'
} Incorrectly assuming that For the specific case of the minimal reproduction, it can be fixed using the recommended -import { parse as parseUrl } from 'url'
+import { pathToFileURL } from 'url'
// ...
export function injectQuery(url: string, queryToInject: string) {
- const { pathname, search, hash } = parseUrl(url)
+ const { pathname, search, hash } = pathToFileURL(url)
return `${pathname}?${queryToInject}${search ? `&` + search.slice(1) : ''}${
hash || ''
}`
} ...but this causes a lot of other tests to fail. |
Describe the bug
On Windows,
vite
can incorrectly resolve thesvelte
runtime as both in and out of root, which causes two instances of the svelte runtime to be loaded. This issue does not seem to appear in Unix systems.In the reproduction logs below, we can see:
svelte/internal
from@svitejs/vite-plugin-svelte
and fromsvelte-hmr
is resolved as/node_modules/svelte/internal/index.mjs
./internal/index.mjs
from insidesvelte/index.mjs
is resolved as/@fs/Users/GrygrFlzr/Documents/projects/vite-windows-imports/node_modules/svelte/internal/index.mjs
In the browser's network tab:
The problem is likely in the import normalization:
vite/packages/vite/src/node/plugins/importAnalysis.ts
Lines 182 to 192 in 76f3535
Reproduction
Tested with
npm
,yarn
, andpnpm
- all reproduce the bug.https://github.com/GrygrFlzr/vite-windows-imports
The reproduction makes use of svelte's
setContext
to better illustrate the bug causing two svelte runtimes to be loaded.npm
Browser error:
System Info
vite
version: 2.0.5The text was updated successfully, but these errors were encountered: