rewriteDefault in @vue/compiler-sfc does not support syntax ` export { default } from '...' ` and occurs SyntaxError
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:https://github.com/vitejs/vite/issues/8008 Relative PR: https://github.com/vitejs/vite/pull/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;