Skip to content
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

Vite generates an empty JS file (which shouldn't exist) #6913

Closed
7 tasks done
davidmz opened this issue Feb 14, 2022 · 7 comments · Fixed by #16078
Closed
7 tasks done

Vite generates an empty JS file (which shouldn't exist) #6913

davidmz opened this issue Feb 14, 2022 · 7 comments · Fixed by #16078
Labels
feat: css p2-nice-to-have Not breaking anything but nice to have (priority)

Comments

@davidmz
Copy link

davidmz commented Feb 14, 2022

Describe the bug

In some conditions, vite build generates an empty js file that has no source. I tried to create a minimal reproduction, please see the attached link to stackblitz.

Run vite build (or just see an existing 'dist' folder there). It generates an empty 'assets/qa-item.00ef0854.js' file that is used in generated page1.html and page2.html. But the sources of these files has no js links.

Reproduction

https://stackblitz.com/edit/vitejs-vite-1fn6ez

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (4) x64 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
    Memory: 17.82 GB / 47.89 GB
  Binaries:
    Node: 14.17.6 - C:\PROGRAM FILES\NODEJS\node.EXE
    Yarn: 1.22.15 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.14.15 - C:\PROGRAM FILES\NODEJS\npm.CMD
  Browsers:
    Chrome: 98.0.4758.82
    Edge: Spartan (44.19041.1266.0), Chromium (98.0.1108.50)
    Internet Explorer: 11.0.19041.1202

Used Package Manager

npm

Logs

No response

Validations

@jianqi-jin
Copy link
Contributor

@davidmz Why the input is .html file? Try the .js file directly.

@bluwy
Copy link
Member

bluwy commented Feb 19, 2022

It's important to note that this only happens with build.cssCodeSplit: false. Vite seems to generate a qa-item.<hash>.js mapping the source qa-item.css. And if you set build.minify: false, you can see there is content in the qa-item.<hash>.js file, which is simply var qaItem = "";. After esbuild minifies and removes it, the file becomes empty which comes to this issue.

@thasmo
Copy link

thasmo commented Jun 26, 2022

For us this happens with build.cssCodeSplit: false for lazily loaded JS files (import()) which only import CSS files.

Reproduction Code: https://github.com/thasmo/vite-6913

@Erutan409
Copy link

Anyone find a resolution to this?

@VaJoy

This comment was marked as spam.

@Mohammad-Ravand

This comment was marked as spam.

@emkayy
Copy link

emkayy commented Apr 12, 2023

I get a file dev-html-ddf0fdd4.js since my source files are inside dev/html/ with the content:

/* empty css                */

@sapphi-red sapphi-red added the p2-nice-to-have Not breaking anything but nice to have (priority) label Mar 1, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: css p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
9 participants