fix(vite): dedupe shared deps to avoid duplicate React from dashgui
dashgui is a local symlinked package with its own nested node_modules containing a second copy of react/@mui/@emotion. Vite bundled that nested React into a dep chunk, causing 'Cannot read properties of null (reading 'useContext')' on routes rendering dashgui/MUI components. Dedupe forces these shared packages to resolve from dashfront's single tree.
This commit is contained in:
@@ -62,6 +62,29 @@ function hasRequestBody(method) {
|
||||
return method === 'POST' || method === 'PUT' || method === 'PATCH';
|
||||
}
|
||||
|
||||
// dashgui is a local (symlinked) package with its own nested node_modules.
|
||||
// Its nested react/@mui/@emotion copies would otherwise get bundled in,
|
||||
// producing a duplicate React instance and "Cannot read properties of null
|
||||
// (reading 'useContext')" at runtime. Dedupe forces these to resolve from
|
||||
// dashfront's tree. (dashgui's own package.json "exports" map already points
|
||||
// the dashgui/* subpaths at its src/, so no alias is needed.)
|
||||
const sharedDeps = [
|
||||
'react',
|
||||
'react-dom',
|
||||
'react/jsx-runtime',
|
||||
'react/jsx-dev-runtime',
|
||||
'react-router',
|
||||
'react-router-dom',
|
||||
'@emotion/react',
|
||||
'@emotion/styled',
|
||||
'@mui/material',
|
||||
'@mui/icons-material',
|
||||
];
|
||||
|
||||
const sharedResolve = {
|
||||
dedupe: sharedDeps,
|
||||
};
|
||||
|
||||
const sharedServer = {
|
||||
// HTTP :4209 — HTTPS :4308 (self-signed; see npm run cert / dev:https)
|
||||
port: useHttps ? 4308 : 4209,
|
||||
@@ -127,6 +150,7 @@ const sharedServer = {
|
||||
};
|
||||
|
||||
export default defineConfig(({ command }) => ({
|
||||
resolve: sharedResolve,
|
||||
build: {
|
||||
rolldownOptions: {
|
||||
output: {
|
||||
|
||||
Reference in New Issue
Block a user