-
-
Notifications
You must be signed in to change notification settings - Fork 213
Description
Description
I have a custom Babel transformation which I'd like to apply using this plugin. I'm also using Remix
plugins: [
remix(),
viteReact({
babel: {
plugins: ['my-babel-plugin']
},
})
]With this setup, I get this error: "Uncaught SyntaxError: Identifier 'RefreshRuntime' has already been declared"
I think the problem is that both plugins are attempting to import the same thing. I tried playing with the order, but doesn't matter.
Here's the fragment containing the problem:
import { createHotContext as __vite__createHotContext } from "/@vite/client";import.meta.hot = __vite__createHotContext("/app/root.tsx");import RefreshRuntime from "/@id/__x00__virtual:remix/hmr-runtime";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( "Remix Vite plugin can't detect preamble. Something is wrong." ); } prevRefreshReg = window.$RefreshReg$; prevRefreshSig = window.$RefreshSig$; window.$RefreshReg$ = (type, id) => { RefreshRuntime.register(type, "/path/to/root.tsx" + " " + id) }; window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;}var _s2 = $RefreshSig$();
import __vite__cjsImport2_react_jsxDevRuntime from "/node_modules/.vite/deps/react_jsx-dev-runtime.js?v=06d7f284"; const jsxDEV = __vite__cjsImport2_react_jsxDevRuntime["jsxDEV"];
import RefreshRuntime from "/@react-refresh";
Suggested solution
Add a config option e.g. enableFastRefresh, defaulting to true (current behaviour), to opt-out of fast refresh behaviour
Alternative
I could write my own vite plugin which is just a copy-paste of this one with the fast refresh stuff removed
Additional context
Since viteReact returns an array of plugins, I tried hackily using the 0-th item (the babel one), but it doesn't work because the two are tied together: the babel one applies some things required for fast refresh.
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.