Skip to content

Commit

Permalink
fix: opt out of direct import in SSR when the file is not JS
Browse files Browse the repository at this point in the history
  • Loading branch information
cyco130 committed Jun 3, 2022
1 parent 01b5ebf commit 5893a4d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/vite/src/node/ssr/ssrModuleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ async function instantiateModule(

const ssrImport = async (dep: string) => {
if (dep[0] !== '.' && dep[0] !== '/') {
return nodeImport(dep, mod.file!, resolveOptions)
const imported = await nodeImport(dep, mod.file!, resolveOptions)
if (imported) {
return imported
}
}
dep = unwrapId(dep)
if (!isCircular(dep) && !pendingImports.get(dep)?.some(isCircular)) {
Expand Down Expand Up @@ -291,6 +294,10 @@ async function nodeImport(
? { ...resolveOptions, tryEsmOnly: true }
: resolveOptions
)
// These cannot be imported directly
if (url.match(/\.(css|less|sass|scss|styl|stylus|pcss|postcss|json)$/)) {
return null
}
if (usingDynamicImport) {
url = pathToFileURL(url).toString()
}
Expand Down

0 comments on commit 5893a4d

Please sign in to comment.