Skip to content

fix: ssrExternal should not skip nested dependencies #7154

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

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/vite/src/node/ssr/__tests__/ssrExternal.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { stripNesting } from '../ssrExternal'

test('stripNesting', async () => {
expect(stripNesting(['c', 'p1>c1', 'p2 > c2'])).toEqual(['c', 'c1', 'c2'])
})
14 changes: 14 additions & 0 deletions packages/vite/src/node/ssr/ssrExternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ import { createFilter } from '@rollup/pluginutils'

const debug = createDebugger('vite:ssr-external')

/**
* Converts "parent > child" syntax to just "child"
*/
export function stripNesting(packages: string[]) {
return packages.map((s) => {
const arr = s.split('>')
return arr[arr.length - 1].trim()
})
}

/**
* Heuristics for determining whether a dependency should be externalized for
* server-side rendering.
Expand All @@ -22,6 +32,10 @@ export function resolveSSRExternal(
config: ResolvedConfig,
knownImports: string[]
): string[] {
// strip nesting since knownImports may be passed in from optimizeDeps which
// supports a "parent > child" syntax
knownImports = stripNesting(knownImports)

const ssrConfig = config.ssr
if (ssrConfig?.noExternal === true) {
return []
Expand Down