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

SSR throws Syntax Error for valid JavaScript #2409

Closed
3 tasks done
JeffSchofield opened this issue Mar 6, 2021 · 1 comment · Fixed by #2417
Closed
3 tasks done

SSR throws Syntax Error for valid JavaScript #2409

JeffSchofield opened this issue Mar 6, 2021 · 1 comment · Fixed by #2417

Comments

@JeffSchofield
Copy link

Describe the bug

Vite in library mode can produce minified code that looks something like this shape:

// some-library.es.js
import { inject as x } from 'vue'

function setup() {
	const { test: x } = { test: true }
}

The use of two x comes from the minifier doing its thing and should be valid. For some reason this shape (where x is used in two spots) causes the syntax error Illegal property in declaration context when instantiating the module at this line: https://github.com/vitejs/vite/blob/master/packages/vite/src/node/ssr/ssrModuleLoader.ts#L122.

I am not familiar with the internals but I believe that the syntax error is introduced at some point in this transform step: https://github.com/vitejs/vite/blob/master/packages/vite/src/node/ssr/ssrTransform.ts#L26

Reproduction

https://github.com/JeffSchofield/vite-ssr-bug

System Info

  • vite version: 2.0.5
  • Operating System: Windows 10 18363.1379
  • Node version: 15.11.0
  • Package manager (npm/yarn/pnpm) and version: yarn 1.22.10
@JeffSchofield
Copy link
Author

JeffSchofield commented Mar 7, 2021

I am certain this is an edge case in the SSR transformation step. Here is the transformed code that is throwing the error from my repro:

const __vite_ssr_import_0__ = __vite_ssr_import__("vue")


__vite_ssr_exports__.default = {
        install() {
                const { test: __vite_ssr_import_0__.inject } = { test: true }
                console.log(__vite_ssr_import_0__.inject)
        }
}

So it seems x is blanket replaced which is introducing the syntax error.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants