Describe the bug
On the server side, we hope the third-party module will be externalized correctly.
If I set an alias for the third-party module, Vite will transform the URL to a local file system path instead of an externalized path. Even though I set ssr.external to the module.
It's a simple reproduct code
// server-entry.js
import * as Vue from 'vue'
// vite.config.js
import { resolve } from 'node:path'
import { defineConfig } from 'vite'
// in order to trigger ssr server restart
export default defineConfig({
resolve: {
alias: {
vue: resolve(process.cwd(), 'node_modules/vue'),
},
},
ssr: {
external: ['vue'],
},
})
After running dev with this config below, server-entry will be transfrormd to this code
import * as Vue from "/@fs/xxx/node_modules/.pnpm/vue@3.5.18_typescript@5.7.3/node_modules/vue/index.mjs"
It's not expected.
I remember this logic is expected in vite@^2.0.0.
We use alias for Vue or React to keep a single instance on the client-side, and we don't want to split client-config and server-config to seperate config files. I hope Vite can handle the externalized module path correctly even if I set an alias.
If you agree with my opinion, I will be happy to provide a pull request for it.
Reproduction
git@github.com:zhangyuang/vite-ssr-external-bug.git
Steps to reproduce
$ git clone git@github.com:zhangyuang/vite-ssr-external-bug.git
$ cd vite-ssr-external-bug && yarn && npm run dev
System Info
System:
OS: macOS 15.5
CPU: (14) arm64 Apple M4 Pro
Memory: 2.76 GB / 48.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 24.4.1 - ~/Library/pnpm/node
Yarn: 1.22.22 - ~/Library/pnpm/yarn
npm: 10.8.2 - ~/Library/pnpm/npm
pnpm: 10.13.1 - ~/Library/pnpm/pnpm
Browsers:
Chrome: 138.0.7204.169
Firefox Nightly: 140.0a1
Safari: 18.5
Used Package Manager
yarn
Logs
No response
Validations
Describe the bug
On the server side, we hope the third-party module will be externalized correctly.
If I set an alias for the third-party module, Vite will transform the URL to a local file system path instead of an externalized path. Even though I set
ssr.externalto the module.It's a simple reproduct code
After running dev with this config below,
server-entrywill be transfrormd to this codeIt's not expected.
I remember this logic is expected in
vite@^2.0.0.We use alias for
VueorReactto keep a single instance on the client-side, and we don't want to split client-config and server-config to seperate config files. I hope Vite can handle the externalized module path correctly even if I set an alias.If you agree with my opinion, I will be happy to provide a pull request for it.
Reproduction
git@github.com:zhangyuang/vite-ssr-external-bug.git
Steps to reproduce
System Info
System: OS: macOS 15.5 CPU: (14) arm64 Apple M4 Pro Memory: 2.76 GB / 48.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 24.4.1 - ~/Library/pnpm/node Yarn: 1.22.22 - ~/Library/pnpm/yarn npm: 10.8.2 - ~/Library/pnpm/npm pnpm: 10.13.1 - ~/Library/pnpm/pnpm Browsers: Chrome: 138.0.7204.169 Firefox Nightly: 140.0a1 Safari: 18.5Used Package Manager
yarn
Logs
No response
Validations