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

rewriteDefault in @vue/compiler-sfc does not support syntax export { default } from '...' and occurs SyntaxError #5935

Closed
511581884 opened this issue May 17, 2022 · 1 comment · Fixed by #5937

Comments

@511581884
Copy link

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-d9ekar?file=src/components/HelloWorld.vue

Steps to reproduce

After open the above reproduction, you will see the console shows the error: Uncaught SyntaxError: Duplicate export of 'default'

Relative Issue:vitejs/vite#8008
Relative PR: vitejs/vite#8016

This problem was firstly discovered in vite/plugin-vue. The reason is that vite/plugin-vue use rewriteDefault function to transform some code like export default, but rewriteDefault function does not consider the syntax export { default } from '...', it causes the syntax error in vite project.

What is expected?

rewriteDefault can transform export { default } from '...' into import xxx from '...'; const ${as} = xxx;
so that vite can work correctly

What is actually happening?

rewriteDefault just ignore the syntax export { default } from '...' and makes vite project wrong.

System Info

System:
    OS: Windows 10 10.0.19042
    CPU: (8) x64 Intel(R) Core(TM) i5-8300H CPU @ 2.30GHz
    Memory: 1.08 GB / 7.86 GB
Binaries:
    Node: 14.17.3 - D:\app\nodejs\node.EXE
    Yarn: 1.22.10 - D:\app\nodejs\node_global\yarn.CMD
    npm: 6.14.13 - D:\app\nodejs\npm.CMD
Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (101.0.1210.32), ChromiumDev

Any additional comments?

I had created a PR for vite to solve this problem, but vite maintainers tell me that may be the problem is in rewriteDefault of @vue/compiler-sfc.
I wonder if it is suitable to let rewriteDefault function transform export { default } from '...' into import xxx from '...'; const ${as} = xxx;

@liulinboyi
Copy link
Member

Preview

@github-actions github-actions bot locked and limited conversation to collaborators Sep 26, 2023
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