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

multiple vite bundle import in one page throw:Uncaught SyntaxError: Identifier 'React' has already been declared #10822

Closed
7 tasks done
joebnb opened this issue Nov 8, 2022 · 5 comments

Comments

@joebnb
Copy link

joebnb commented Nov 8, 2022

Describe the bug

when multiple vite bundle import in one page will throw " Identifier 'Fa' has already been declared " in console.
image

bundle 1 fold level 1 screenshot:
image

the bundle 2 fold level 1 screenshot:
image

image

i have already to try:

  • set minify with false in one of bunde
  • switch minify to terser and disable mangle and compress

it's still output some mangled variable was decleared.

when set both bundle with minify false it output:

image

my vite config is

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [react()],
    build: {
        outDir: '../../lib/client',
        manifest: true,
        target: 'es2020',
        rollupOptions: {
            output: {
                chunkFileNames: 'assets/[name].js',
                entryFileNames: 'assets/[name].js',
                assetFileNames: 'assets/[name].[ext]',
                manualChunks: {},
            },
        },
        minify: false,
    },
    server: {
        host: '0.0.0.0',
        port: 3000,
        cors: {
            origin: '*',
        },
    },
});

how could i to fix it, PuruVJ/vite-preset-react#5 i found this issue during write this,not sure did this is helpful to solve this.

Reproduction

no

Steps to reproduce

No response

System Info

System:
    OS: macOS 13.0
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 108.93 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.12.0 - /usr/local/bin/node
    npm: 8.19.3 - /usr/local/bin/npm
  Browsers:
    Chrome: 107.0.5304.87
    Safari: 16.1

Used Package Manager

npm

Logs

No response

Validations

@joebnb
Copy link
Author

joebnb commented Nov 8, 2022

if one is import with vite dev model it's works well

@joebnb joebnb changed the title multiple vite bundle import in one page throw:Uncaught SyntaxError: Identifier 'Fa' has already been declared multiple vite bundle import in one page throw:Uncaught SyntaxError: Identifier 'React' has already been declared Nov 8, 2022
@joebnb
Copy link
Author

joebnb commented Nov 9, 2022

if wrap with a IIFE it's works as expect
image

i think it's a bug of vite,it should be fix

@github-actions
Copy link

Hello @joebnb. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 27, 2022
@luwes
Copy link

luwes commented Dec 8, 2022

this seems still to be a bug, at least with Nuxt 3.

Vite injected this import at the top of our minified bundles with no regard for variable collision

import { h } from '/_nuxt/node_modules/.vite/deps/vue.js?v=8f0c34a1';

@joebnb
Copy link
Author

joebnb commented Dec 8, 2022

vuejs/core#7206 vue3 also have this problem

@github-actions github-actions bot locked and limited conversation to collaborators Dec 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants