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

mergeConfig doesn't merge plugin configuration #16479

Closed
7 tasks done
alan-nf opened this issue Apr 20, 2024 · 2 comments
Closed
7 tasks done

mergeConfig doesn't merge plugin configuration #16479

alan-nf opened this issue Apr 20, 2024 · 2 comments

Comments

@alan-nf
Copy link

alan-nf commented Apr 20, 2024

Describe the bug

mergeConfig is documented to "Deeply merge two Vite configs" but it seems to stop at plugins. If you have two configs, each defining the same plugin with different options, instead of merging it and having one entry for the plugin, we get two, and resulting errors. See Stackblitz for example where two react plugin entries cause errors.

Reproduction

https://stackblitz.com/edit/vitejs-vite-awhsbt?file=vite.config.ts

Steps to reproduce

stackblitz should show the errors right away. Look at vite.config.ts to see the react(...) plugin entries causing the problems

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.3 - /usr/local/bin/pnpm
  npmPackages:
    @vitejs/plugin-react: ^4.2.1 => 4.2.1 
    vite: ^5.2.8 => 5.2.9

Used Package Manager

npm

Logs

Click to expand!
3:36:18 PM [vite] Pre-transform error: Transform failed with 3 errors:
/home/projects/vitejs-vite-awhsbt/src/App.tsx:1:1023: ERROR: The symbol "inWebWorker" has already been declared
/home/projects/vitejs-vite-awhsbt/src/App.tsx:1:1119: ERROR: The symbol "prevRefreshReg" has already been declared
/home/projects/vitejs-vite-awhsbt/src/App.tsx:1:1138: ERROR: The symbol "prevRefreshSig" has already been declared
3:36:18 PM [vite] Internal server error: Transform failed with 3 errors:
/home/projects/vitejs-vite-awhsbt/src/App.tsx:1:1023: ERROR: The symbol "inWebWorker" has already been declared
/home/projects/vitejs-vite-awhsbt/src/App.tsx:1:1119: ERROR: The symbol "prevRefreshReg" has already been declared
/home/projects/vitejs-vite-awhsbt/src/App.tsx:1:1138: ERROR: The symbol "prevRefreshSig" has already been declared
  Plugin: vite:esbuild
  File: /home/projects/vitejs-vite-awhsbt/src/App.tsx:1:32
  
  The symbol "inWebWorker" has already been declared
  1  |  import RefreshRuntime from "/@react-refresh";const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;let prevRefreshReg;let prevRefreshSig;if (import.meta.hot && !inWebWorker) {  if (!window.__vite_plugin_react_preamble_installed__) {    throw new Error(      "@vitejs/plugin-react can't detect preamble. Something is wrong. " +      "See https://github.com/vitejs/vite-plugin-react/pull/11#discussion_r430879201"    );  }  prevRefreshReg = window.$RefreshReg$;  prevRefreshSig = window.$RefreshSig$;  window.$RefreshReg$ = (type, id) => {    RefreshRuntime.register(type, "/home/projects/vitejs-vite-awhsbt/src/App.tsx" + " " + id)  };  window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;}var _s2 = $RefreshSig$();globalThis.jotaiAtomCache = globalThis.jotaiAtomCache || { cache: new Map(), get(name, inst) {if (this.cache.has(name)) {return this.cache.get(name);}this.cache.set(name, inst);return inst;} };import RefreshRuntime from "/@react-refresh";const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;let prevRefreshReg;let prevRefreshSig;if (import.meta.hot && !inWebWorker) {if (!window.__vite_plugin_react_preamble_installed__) {throw new Error("@vitejs/plugin-react can't detect preamble. Something is wrong. " + "See https://github.com/vitejs/vite-plugin-react/pull/11#discussion_r430879201");}prevRefreshReg = window.$RefreshReg$;prevRefreshSig = window.$RefreshSig$;window.$RefreshReg$ = (type, id) => {RefreshRuntime.register(type, "/home/projects/vitejs-vite-awhsbt/src/App.tsx" + " " + id);};window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;}var _s = $RefreshSig$();import { useState } from 'react';

Validations

Copy link

stackblitz bot commented Apr 20, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@bluwy
Copy link
Member

bluwy commented Apr 29, 2024

Plugins are not merged because it's not possible to merge it.

  • Two plugins could have same name but runs in different order (enforce).
  • Two plugins with the same names are acceptable as long as they don't overlap (e.g. the includes option is used to transform specific files only). In which case, Vite shouldn't merge them.
  • Two plugins may contain their own separate state in a closure, and it can't be combined.
  • Some plugins are not meant/accounted to be used multiple times. It shouldn't be used multiple times in the first place in that case.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants