Skip to content
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

Latest @vitejs/plugin-legacy breaks ssr build #4818

Closed
7 tasks done
tjk opened this issue Sep 1, 2021 · 4 comments
Closed
7 tasks done

Latest @vitejs/plugin-legacy breaks ssr build #4818

tjk opened this issue Sep 1, 2021 · 4 comments

Comments

@tjk
Copy link
Contributor

tjk commented Sep 1, 2021

Describe the bug

Copied from #4767 (comment):

$ 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

@patak-dev
Copy link
Member

I think this may be surfacing another bug, now that the banner includes the export. But the banner shouldn't be there. We have #4536 to disable plugin-legacy during SSR build, so maybe the solution is to merge it. @tjk would you check it out?
@nulladdict if not, I think the logic to when to add the banner may need to be improved. It is a bit strange we didn't get a report before this though, wouldn't it still be invalid before?

@nulladdict
Copy link
Contributor

Yes, when I wrote this check I kind of assumed there's only one entry and it's the client one. I'm not too familiar with ssr, so I don't know if legacy plugin should or shouldn't be ran during the server build.

I took a look at the bundled entry-server.js in ssr-vue example and I think this didn't surface before because calling import() is still valid inside cjs, but using both export and exports is not.

I think it might be a good idea to add legacy+ssr test, so things like this can be caught in the future, maybe as a part of #4536

@tjk
Copy link
Contributor Author

tjk commented Sep 2, 2021

I left some random thoughts in there. I currently run the vite --ssr command with an environment variable to distinguish upfront rather than at config resolution, so I can more easily "disable" the legacy-plugin and see if that works...

@tjk
Copy link
Contributor Author

tjk commented Sep 8, 2021

This should be fixed in @vitejs/plugin-legacy 1.5.3 (after 1f068fc and fdc3212)

@tjk tjk closed this as completed Sep 8, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Sep 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants