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

The syntax export { default } from ... in vue file leads to Uncaught SyntaxError: Duplicate export of 'default' #8008

Closed
7 tasks done
511581884 opened this issue May 4, 2022 · 1 comment
Labels
bug: upstream Bug in a dependency of Vite p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@511581884
Copy link

511581884 commented May 4, 2022

Describe the bug

if you write export { default } from ... at script block in vue file, the result is:

  • in dev, the broswer will tell you: Uncaught SyntaxError: Duplicate export of 'default'
  • in prod, the terminal will tell you: [rollup-plugin-dynamic-import-variables] Duplicate export 'default'

index.ts

import { ref } from 'vue';
export default {
  setup() {
    const count = ref(1);
    return {
      count,
    };
  },
};

index.vue

<template>
  <h1>{{ count }}</h1>
</template>

<script>
export { default } from './index';
</script>

<style ></style>

if you run npm run dev, the browser shows:
image

if you run npm run build, the terminal shows:
image

If I write a plugin to transform all export {default} from ... into import xxx from xxx; export default xxx, then vite works corretcly.
Or if I change the following source code about genScriptCode in plugin-vue/src/main.ts, just add a judgement condition, it also works corretcly.
image

It seems that the problem is in the @vitejs/plugin-vue, the above syntax is not considered in this plugin.

Reproduction

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

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

Used Package Manager

npm

Logs

[rollup-plugin-dynamic-import-variables] Duplicate export 'default' (13:7)
file: E:/project/vite-vue3-ts-example/src/components/HelloWorld.vue:13:7
error during build:
SyntaxError: Duplicate export 'default' (13:7)
    at Parser.pp$4.raise (E:\project\vite-vue3-ts-example\node_modules\_rollup@2.71.1@rollup\dist\shared\rollup.js:19704:13)
    at Parser.pp$8.checkExport (E:\project\vite-vue3-ts-example\node_modules\_rollup@2.71.1@rollup\dist\shared\rollup.js:17958:12)
    at Parser.pp$8.parseExport (E:\project\vite-vue3-ts-example\node_modules\_rollup@2.71.1@rollup\dist\shared\rollup.js:17901:10)
    at Parser.pp$8.parseStatement (E:\project\vite-vue3-ts-example\node_modules\_rollup@2.71.1@rollup\dist\shared\rollup.js:17174:74)
    at Parser.pp$8.parseTopLevel (E:\project\vite-vue3-ts-example\node_modules\_rollup@2.71.1@rollup\dist\shared\rollup.js:17055:21)
    at Parser.parse (E:\project\vite-vue3-ts-example\node_modules\_rollup@2.71.1@rollup\dist\shared\rollup.js:16827:15)
    at Function.parse (E:\project\vite-vue3-ts-example\node_modules\_rollup@2.71.1@rollup\dist\shared\rollup.js:16877:35)
    at Graph.contextParse (E:\project\vite-vue3-ts-example\node_modules\_rollup@2.71.1@rollup\dist\shared\rollup.js:22981:38)
    at Object.transform (E:\project\vite-vue3-ts-example\node_modules\_vite@2.9.7@vite\dist\node\chunks\dep-88bd5805.js:19769:27)
    at E:\project\vite-vue3-ts-example\node_modules\_rollup@2.71.1@rollup\dist\shared\rollup.js:22834:37
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! create@0.0.0 build: `vite build --debug`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the create@0.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Validations

@sapphi-red
Copy link
Member

Closing as it is fixed by vuejs/core#5937 which is released on Vue 3.2.34.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug: upstream Bug in a dependency of Vite p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants