Latest @vitejs/plugin-legacy breaks ssr build
Describe the bug
Copied from https://github.com/vitejs/vite/pull/4767#issuecomment-910554565:
$ vite build --ssr src/entry-server.ts --outDir dist/ssr
~/dist/ssr/entry-server.js:36
export function __vite_legacy_guard() {
^^^^^^
SyntaxError: Unexpected token 'export'
at wrapSafe (internal/modules/cjs/loader.js:984:16)
at Module._compile (internal/modules/cjs/loader.js:1032:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:933:32)
at Function.Module._load (internal/modules/cjs/loader.js:774:14)
at Module.require (internal/modules/cjs/loader.js:957:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
Reproduction
https://github.com/tjk/vite-ssr-plugin-legacy-build-issue
System Info
System:
OS: macOS 11.2.3
CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
Memory: 198.71 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.17.0 - ~/.asdf/installs/nodejs/14.17.0/bin/node
Yarn: 1.22.5 - ~/.asdf/shims/yarn
npm: 6.14.13 - ~/.asdf/installs/nodejs/14.17.0/bin/npm
Browsers:
Chrome: 92.0.4515.159
Firefox: 86.0
Safari: 14.0.3
npmPackages:
@vitejs/plugin-vue: ^1.0.0 => 1.6.0
vite: ^2.5.3 => 2.5.3
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 https://github.com/vuejs/vue-next 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.