-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Description
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/[email protected][email protected]/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
[email protected]:zhangyuang/vite-ssr-external-bug.git
Steps to reproduce
$ git clone [email protected]: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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.