Vite Pre-transform error after upgrade
Problem
After upgrade elm pages to 10.0.3 and vite to "^5.0.11" I started getting this error in my project on page loads on the dev server. I get the same error both in my personal project and in elm-pages-starter.
[vite] Pre-transform error: Failed to load url /elm-pages.js (resolved id: /elm-pages.js). Does the file exist? (x2)
1 /: 35.617ms
The site still runs and elm-pages.js gets downloaded without errors in the browser.
Search results
Found this Issue on another project which might be related https://github.com/storybookjs/storybook/issues/25256 . Seems like it has to do with some change in version 5 of vite. This was the "fix" they did in that project https://github.com/storybookjs/storybook/pull/25329/files . Not sure how and if this translates to elm-pages or if it's related at all.
Workaround
From/inspired by https://github.com/vitejs/vite/issues/15374#issuecomment-1859842971
// in elm-pages.config.mjs
vite: defineConfig({
assetsInclude: ['/elm-pages.js']
}),
Some more digging. ~Maybe a fix is on its way https://github.com/vitejs/vite/issues/15354#issuecomment-1874899619~ Edit the fix for this seems to have been merged in 5.0.11 already so it probably did not help us https://github.com/vitejs/vite/pull/15361
Oh nice, that's very helpful! Thank you for looking into that and saving me the time @Mousaka! 🙏
Updated the issue:
- Added a workaround I found.
- Added to problem description that I do not only get this in my personal project, I also get it in elm-pages-starter.
Edit the fix for this seems to have been merged in 5.0.11 already so it probably did not help us https://github.com/vitejs/vite/pull/15361
How do you know it endedd up in 5.0.11?
I couldn't tell immediately from looking at the issue which release it would be a part of. Worth checking and seeing when the next release comes out if it's fixed.
Oh yes, I see it now in https://github.com/vitejs/vite/blob/v5.0.12/packages/vite/CHANGELOG.md#5011-2024-01-05.
Strange that it's still there then. Maybe not related to that fix at all.
I'm not sure why this is needed now, but it's easy enough to add that to the built-in Vite defaults so I'll go ahead and do that. Thanks for figuring out the fix!
This will go out with the next elm-pages release.
Looks like that Vite fix didn't resolve it, but I believe this open Vite issue tracks the problem: https://github.com/vitejs/vite/issues/6582