-
-
Notifications
You must be signed in to change notification settings - Fork 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 Error: Function called outside component initialization #460
Comments
I can confirm I see that on Windows, not Linux. Apparently one Svelte runtime is resolved / rewritten by Vite from "inside Vite's project root", whereas another one is resolved from "outside", resulting in an import ULR for The Those are only casual observations for now, because I have a hell of a hard time debugging on Windows, but it feels like Vite is doing something like Maybe it's our fault, sending backslashes and slashes on different occasions, but I still feel this difference should be ironed out on Windows, at Vite level, so maybe there would be something to do there as well. |
Closing in on the cause. In the end, it's not a backslash, it's a It happens here. Vite transforms paths inside project root (i.e. Vite's Vite sees its project root as The problem is, for the the same file, it sometime receives the path as In our case, it sees In fact, it seems that on Windows most "inside root" paths are incorrectly cast to absolute URLs of the This means the bug fix probably belongs neither in Kit, nor in the Vite plugin. I'm not sure where it really belongs, but I have a strong suspicion that it is in This also means this bug should not be specific to pnpm. @GrygrFlzr can you check if you have this same problem with yarn or npm? |
Thanks to @rixo's findings I managed to repro this using:
Without needing kit. See https://github.com/GrygrFlzr/vite-windows-imports which reproduces this with all three (npm / yarn / pnpm). |
Here's the full dependency tree of the minimal repro above: Dependency Tree
|
So to sum up: Importing Importing Does this narrow it down to being an issue with |
It might be worth making Vite aware of the Windows specific issue but I still believe it's a problem in I'm looking to see if I can make a very minimal repro with just this plugin. |
Hmm... After some quick experimentation, both Rollup and Don't have much more time to investigate right now... But I think it's a good thing that there's an issue in Vite's tracker. |
I missed your earlier comment (shouldn't do things in a hurry 😅 ). Indeed it's not in there... I don't know if Vite is bundling it or reimplementing it. Rather seems the latter, since they apparently behave differently. |
PR pending for this at vitejs/vite#2435 |
This is caused by Vite loading two separate
svelte
runtimes which causes things likesetContext
to fail. There is no workaround, as this requires a change in Vite's import normalization.Describe the bug
Starting a new project using the main branch of
kit
results in an overlay error, and the component isn't interactive.Logs
Browser console
Overlay error
To Reproduce
In the
kit
monorepo:In another project folder:
npm init svelte@next # no to typescript, use css
Point
package.json
's@sveltejs/kit
to the path of thekit
package:Then install the dependencies and run dev:
Expected behavior
No errors
Information about your SvelteKit Installation:
@sveltejs/kit
commit 055a822Severity
Unusable.
Additional context
pnpm
is required to support the monorepo linking.I'm not entirely sure what's Windows-specific about this issue, but our CI seems to report success for the Ubuntu tests: https://github.com/sveltejs/kit/runs/2046784747
The text was updated successfully, but these errors were encountered: