diff --git a/vite.config.js b/vite.config.js index 59d2b24..29cf599 100644 --- a/vite.config.js +++ b/vite.config.js @@ -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: {