vite
vite copied to clipboard
fix: opt out of direct import in SSR when the file is not JS
Description
Currently importing external CSS files in SSR throws ERR_UNKNOWN_FILE_EXTENSION unless those modules are marked as external (reproduction, StackBlitz). This PR solves it by opting out of direct Node import if the resolved file has a non-JS extension.
Additional context
The regex testing if a file is a non-JS file (which I copied from the optimizer code) may require some more thinking.
What is the purpose of this pull request?
- [x] Bug fix
- [ ] New Feature
- [ ] Documentation update
- [ ] Other
Before submitting the PR, please make sure you do the following
- [x] Read the Contributing Guidelines.
- [x] Read the Pull Request Guidelines and follow the Commit Convention.
- [x] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
- [x] Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g.
fixes #123). - [x] Ideally, include relevant tests that fail without this PR but pass with it.
Deploy Preview for vite-docs-main canceled.
| Name | Link |
|---|---|
| Latest commit | fba2ba8d924d53155c89c5664705da2b384e54d5 |
| Latest deploy log | https://app.netlify.com/sites/vite-docs-main/deploys/62bb61fb3227360009423ba5 |
I tested the repro with Vite 2.9.13 and plugin-react 1.3.2, and it seems to work fine. Stackblitz. So this might be a regression in Vite 3.