vite-plugin/vite-plugin-commonjs

[vite] RollupError: Duplicate export 'default'

Opened this issue · 5 comments

const test = [
    { test: 123, add: 123 },
    { test: 123, add: 123 },
    { test: 123, add: 123 },
    { test: 123, add: 123 },
  ]

  test.forEach((module, index) => {
    console.log('🚀 ~ test.forEach ~ module:', module)
    if (index == 1) {
      module.test = 123
    }
  })

The above code example will have a packaging exception

Abnormal information:
ERROR Duplicate export 'default' (Note that you need plugins to import files that are not JavaScript) 11:31:29
204: const CJS__export_default = (module.exports == null ? {} : module.exports).default || module.exports;
205: export {
206: CJS__export_default as default,
^
207: }
208: /* [vite-plugin-commonjs] export-statement-E */

Were you able to find a workaround for this issue?

Can you provide a minimal reproduction repo?

Were you able to find a workaround for this issue?

It looks like module is treated as CommonJS's module. You can try replacing module with module1 or something.

const test = [
    { test: 123, add: 123 },
    { test: 123, add: 123 },
    { test: 123, add: 123 },
    { test: 123, add: 123 },
  ]

-  test.forEach((module, index) => {
+  test.forEach((module1, index) => {
    console.log('🚀 ~ test.forEach ~ module:', module)
    if (index == 1) {
      module.test = 123
    }
  })

It looks like module is treated as CommonJS's module. You can try replacing module with module1 or something.看起来module被视为 CommonJS 的module 。你可以尝试用module1或其他东西替换module

const test = [
    { test: 123, add: 123 },
    { test: 123, add: 123 },
    { test: 123, add: 123 },
    { test: 123, add: 123 },
  ]

-  test.forEach((module, index) => {
+  test.forEach((module1, index) => {
    console.log('🚀 ~ test.forEach ~ module:', module)
    if (index == 1) {
      module.test = 123
    }
  })

This example was written by a business developer. It is necessary to notify all developers to pay attention to this problem, which is too much of a burden. Can this problem be fundamentally fixed in the plug-in?