Skip to content

Commit

Permalink
fix(ssr): no external symlink package (#9296)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jul 22, 2022
1 parent 0602017 commit ea27701
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/vite/src/node/plugins/resolve.ts
Expand Up @@ -656,6 +656,10 @@ export function tryNodeResolve(
if (!externalize) {
return resolved
}
// dont external symlink packages
if (!resolved.id.includes('node_modules')) {
return
}
const resolvedExt = path.extname(resolved.id)
let resolvedId = id
if (isDeepImport) {
Expand Down
5 changes: 5 additions & 0 deletions playground/ssr-deps/__tests__/ssr-deps.spec.ts
Expand Up @@ -98,3 +98,8 @@ test('msg from external using external entry', async () => {
'Hello World!'
)
})

test('msg from linked no external', async () => {
await page.goto(url)
expect(await page.textContent('.linked-no-external')).toMatch('Hello World!')
})
5 changes: 5 additions & 0 deletions playground/ssr-deps/linked-no-external/index.js
@@ -0,0 +1,5 @@
export const hello = function () {
// make sure linked package is not externalized so Vite features like
// import.meta.env works (or handling TS files)
return import.meta.env.DEV && 'Hello World!'
}
6 changes: 6 additions & 0 deletions playground/ssr-deps/linked-no-external/package.json
@@ -0,0 +1,6 @@
{
"name": "linked-no-external",
"private": true,
"type": "module",
"version": "0.0.0"
}
3 changes: 2 additions & 1 deletion playground/ssr-deps/package.json
Expand Up @@ -26,7 +26,8 @@
"optimized-with-nested-external": "file:./optimized-with-nested-external",
"optimized-cjs-with-nested-external": "file:./optimized-with-nested-external",
"external-using-external-entry": "file:./external-using-external-entry",
"external-entry": "file:./external-entry"
"external-entry": "file:./external-entry",
"linked-no-external": "link:./linked-no-external"
},
"devDependencies": {
"cross-env": "^7.0.3",
Expand Down
4 changes: 4 additions & 0 deletions playground/ssr-deps/src/app.js
Expand Up @@ -11,6 +11,7 @@ import onlyObjectAssignedExports from 'only-object-assigned-exports'
import requireAbsolute from 'require-absolute'
import noExternalCjs from 'no-external-cjs'
import importBuiltinCjs from 'import-builtin-cjs'
import { hello as linkedNoExternal } from 'linked-no-external'

// This import will set a 'Hello World!" message in the nested-external non-entry dependency
import 'non-optimized-with-nested-external'
Expand Down Expand Up @@ -75,5 +76,8 @@ export async function render(url, rootDir) {
const externalUsingExternalEntryMessage = externalUsingExternalEntry.hello()
html += `\n<p class="external-using-external-entry">message from external-using-external-entry: ${externalUsingExternalEntryMessage}</p>`

const linkedNoExternalMessage = linkedNoExternal()
html += `\n<p class="linked-no-external">message from linked-no-external: ${linkedNoExternalMessage}</p>`

return html + '\n'
}
5 changes: 5 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ea27701

Please sign in to comment.