-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
fix: use Function instead of eval to dynamically import config files #5213
Conversation
Hey @SamVerschueren! Great to see the StackBlitz team digging into Vite's codebase. The fix looks good to me. I just re-run the jobs, there was a segmentation fault without a clear error. Let's see if it is just a glitch |
Still failing, is the test suite working for you locally @SamVerschueren ? |
@aleclarson is telling me that this may be a GH glitch |
It might be something with the test. Let me dig a bit deeper. |
I found a fix, but I'm not sure if I'm a fan of it. The thing is that Jest seem to enforce the use of Without that flag, Jest seems to choke on the dynamic import. But enabling that flag for all tests just feels a bit weird. What do you guys think? |
The tests still cause a segfault on local as well. If I remove the Jest flag |
i'm seeing this error message, even after changing the fixture from
Which indicates that your addition of I'd rather see if we can find a way to test this via e2e tests that don't cause this problem. eg. playground/cli testsuite does load a vite.config.js with the code of this PR, so it could count as sort of a 'transitive' testcase. One thing i am a bit worried about is the dynamic cache buster query param that isn't part of the dynamicImport function itself, if all usage in vite is requiring this cache buster, it could be inlined to avoid people forgetting it. |
I have to remove the test because it feels like there's nothing I can do myself. I used segfault-handler to dump a crash log and this is what I get.
This does not happen if I remove the |
Note, in vite-plugin-svelte we do use a crude try/catch solution that falls back to require in case dynamic import fails, so that it works even when dynamic import isn't supported. https://github.com/sveltejs/vite-plugin-svelte/blob/4f24b678d930292b62ad69f141580469e48f6224/packages/vite-plugin-svelte/src/utils/load-svelte-config.ts#L28 I'm not sure this would be the right move for vite though, it's more or less just present for legacy cjs projects. (sometimes i wish they'd went for a big breaking change instead of this dual-system compatibility nightmare.) |
I agree, I'd rather not introduce this flag either. If Vite had e2e tests with config files, I think we're fine because then it's covered at a higher level. At first I had the cache buster added inside the |
Also, this PR #5197 for instance does use a dynamic import as well, but without cache buster. I think that was the reason I didn't add it for every import. Maybe that PR also needs it though, in that case it might make sense to add it for everything. |
No thanks. We need to allow caching if ssrModuleLoader is to use this function. |
I tried to verify that the current tests fail if a copy of |
@SamVerschueren do you have a copy of the test that caused the segfault? I'd like to look at it, but it looks like the commits were squashed, so I'm not sure how to reproduce |
Description
Hi Everyone 👋 . I'm a software engineer at StackBlitz. When I tested out the Vite example for Svelte through https://vite.new/svelte I noticed that something broke. After some investigation I could track it down to the
eval()
dynamic import workaround. Currently dynamic imports ineval()
don't work yet, we're looking at implementing them but can't give any estimate when that would be the case. However, dynamic imports do work innew Function()
calls and also make the code a bit cleaner and reusable I guess, but that might be just a personal opinion.After making these changes directly in
node_modules/vite
, it works on StackBlitz as well.If this would be merged, this PR #5197 should make use of the
dynamicImport
method inutils.ts
as well.Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).