-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[plugin:plugin-vue-jsx] Unable to convert tsx correctly when performing server side rendering in SSR mode #2662
Comments
Supplement. The fix I tried is the code below. |
try like this import { defineComponent } from 'vue'
import { RouterView } from 'vue-router'
const component = defineComponent({
name: 'App',
setup() {
return () => <RouterView />
}
})
export default component |
@Ttou 9:48:57 [vite] Error when evaluating SSR module /pages/index.tsx:
ReferenceError: __default__ is not defined
at eval (/pages/index.tsx:16:41)
at instantiateModule (/Users/dadajam4/projects/develops/vite-plugin-vue-jsx-issue-20210324/node_modules/vite/dist/node/chunks/dep-efe32886.js:68893:166)
ReferenceError: __default__ is not defined
at eval (/pages/index.tsx:16:41)
at instantiateModule (/Users/dadajam4/projects/develops/vite-plugin-vue-jsx-issue-20210324/node_modules/vite/dist/node/chunks/dep-efe32886.js:68893:166)
Error: Couldn't resolve component "default" at "/"
at /Users/dadajam4/projects/develops/vite-plugin-vue-jsx-issue-20210324/node_modules/vue-router/dist/vue-router.cjs.js:1998:47
(node:46700) UnhandledPromiseRejectionWarning: Error: Couldn't resolve component "default" at "/"
at /Users/dadajam4/projects/develops/vite-plugin-vue-jsx-issue-20210324/node_modules/vue-router/dist/vue-router.cjs.js:1998:47 |
@Ttou |
I have found that this approach can work around the problem.
Ideally, there should be no problem with the natural syntax of, so keep checking for problems. |
Copying the default export replace block to line 220 fixes it for me vite/packages/plugin-vue-jsx/index.js Lines 196 to 202 in fbecf1e
vite/packages/plugin-vue-jsx/index.js Lines 219 to 227 in fbecf1e
if (ssr) {
if (hasDefault) {
result.code =
result.code.replace(
/export default defineComponent/g,
`const __default__ = defineComponent`
) + `\nexport default __default__`
}
let ssrInjectCode =
`\nimport { ssrRegisterHelper } from "${ssrRegisterHelperId}"` +
`\nconst __moduleId = ${JSON.stringify(id)}`
for (const { local } of hotComponents) {
ssrInjectCode += `\nssrRegisterHelper(${local}, __moduleId)`
}
result.code += ssrInjectCode
} |
This issue gets locked because it has been closed for more than 14 days. |
Describe the bug
The jsx transpiling fails when using vite-ssr and
plugin-vue-jsx
at the same time.I think this is because
__default__
is not processed correctly in the following source code.vite/packages/plugin-vue-jsx/index.js
Lines 207 to 210 in 524a018
The duplication procedure and my fix (I don't know if it's appropriate) can be replicated in the following repository:
Reproduction
It can be reproduced in the following repository.
https://github.com/dadajam4/vite-plugin-vue-jsx-issue-20210324
System Info
Output of
npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:Used package manager: npm 6.14.10
Logs
Before submitting the issue, please make sure you do the following
The text was updated successfully, but these errors were encountered: