vite icon indicating copy to clipboard operation
vite copied to clipboard

fix: opt out of direct import in SSR when the file is not JS

Open cyco130 opened this issue 3 years ago • 2 comments

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.

cyco130 avatar Jun 03 '22 12:06 cyco130

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

netlify[bot] avatar Jun 28 '22 19:06 netlify[bot]

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.

bluwy avatar Jul 01 '22 14:07 bluwy