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
Dynamic CSS import fails due to double slashes #4731
Comments
I'm also seeing this issue with dynamic css. In my case I have await import('./styles/main.scss'); Looking at what Vite is outputting the base path is being added to the call to __vitePreload
and the within the
|
@rynpsc Good catch! Removing the trailing slash for I think the second prefix EDIT: A quick test showed simply removing |
I just tested it with the project you provided. I introduced my patch in Vite 2.4.4. Then I tried 2.4.3. There is no difference between the code built in 2.4.3 and the code built in 2.4.4. I checked 2.5.0 and 2.5.1. In these two versions, changes were made to the dynamic import code. I suspect that these changes caused your problem. And I found that there was a BUG for dynamically importing css in versions prior to 2.5.1, which was fixed in 2.5.1. It may be a problem caused by this aspect, and relevant developers need to check it again. |
I found the problem in the latest code:
The |
Vite 2.5.7 version has been released, you can try to see if this version solves your problem. |
It does! Thank you for the fix @hex-ci. 🙏 |
Describe the bug
When building for production, a dynamic CSS import with relative path fails to load because it starts with double slashes.
This issue occurs only when building for production (
npm run build
), and not when running the development server (npm run dev
).For example, in a script in the root folder, a relative import like this
Results in markup with a path starting with an incorrect double slash like this.
I think I tracked it down to line L48 in
importAnalysisBuild.ts
introduced by #4096If
base
ends with a slash anddep
starts with a slash, string concatenation gives two slashes. With Node, one would usepath.join(base, dep)
for that reason. Not sure if something like that exists for the browser.Reproduction
See https://github.com/vwkd/vite-duplicate-dynamic-import
npm run build && npm run preview
You can see the second erroneous import failing in the network tab and a console error being logged
Note, this issue occurs only when building for production, not when running the dev server.
npm run dev
System Info
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: