Skip to content

Commit

Permalink
fix(ssr): fix ssr external check for mjs entries
Browse files Browse the repository at this point in the history
fix #2161
  • Loading branch information
yyx990803 committed Feb 24, 2021
1 parent 0436b5a commit 5095e04
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/vite/src/node/ssr/ssrExternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ export function resolveSSRExternal(
ssrExternals.add(id)
continue
}
// node resolve and esm resolve resolves to the same file
if (path.extname(entry) !== '.js') {
// entry is not js, cannot externalize
continue
}
if (!entry.includes('node_modules')) {
// entry is not a node dep, possibly linked - don't externalize
// instead, trace its dependencies.
Expand All @@ -74,6 +69,10 @@ export function resolveSSRExternal(
ssrExternals.add(id)
} else {
// node resolve and esm resolve resolves to the same file.
if (!/\.m?js$/.test(entry)) {
// entry is not js, cannot externalize
continue
}
// check if the entry is cjs
const content = fs.readFileSync(entry, 'utf-8')
if (/\bmodule\.exports\b|\bexports[.\[]|\brequire\s*\(/.test(content)) {
Expand Down

0 comments on commit 5095e04

Please sign in to comment.