@@ -3,7 +3,36 @@ import react from "@vitejs/plugin-react";
33
44// https://vitejs.dev/config/
55export default defineConfig ( {
6- plugins : [ react ( ) ] ,
6+ plugins : [
7+ react ( ) ,
8+ {
9+ // Vite 8 / rolldown's CJS→ESM interop calls __toESM with isNodeMode=1,
10+ // which ignores the __esModule flag and wraps the whole exports object as
11+ // the default export. react-plotly.js sets exports.__esModule=true and
12+ // exports.default=PlotComponent, but isNodeMode=1 causes Plot to resolve
13+ // to {__esModule: true, default: PlotComponent} instead of PlotComponent.
14+ //
15+ // Fix: exclude neural-activity-visualizer-react from pre-bundling so Vite
16+ // serves its ESM source directly (triggering this transform), then rewrite
17+ // the import to extract .default explicitly before rolldown sees it.
18+ name : "fix-react-plotly-interop" ,
19+ enforce : "pre" ,
20+ transform ( code , id ) {
21+ if (
22+ id . includes ( "neural-activity-visualizer-react" ) &&
23+ code . includes ( 'import Plot from "react-plotly.js"' )
24+ ) {
25+ return {
26+ code : code . replace (
27+ 'import Plot from "react-plotly.js"' ,
28+ 'import _reactPlotly from "react-plotly.js";\nconst Plot = _reactPlotly.default ?? _reactPlotly;'
29+ ) ,
30+ map : null ,
31+ } ;
32+ }
33+ } ,
34+ } ,
35+ ] ,
736 server : {
837 port : 3000 ,
938 proxy : {
@@ -15,6 +44,14 @@ export default defineConfig({
1544 } ,
1645 } ,
1746 } ,
47+ optimizeDeps : {
48+ // Pre-bundle react-plotly.js so its CJS is converted to ESM before the
49+ // browser sees it. neural-activity-visualizer-react is excluded so Vite
50+ // serves it as raw ESM, which triggers the fix-react-plotly-interop plugin
51+ // transform above (plugin transforms don't run on pre-bundled files).
52+ include : [ "react-plotly.js" ] ,
53+ exclude : [ "neural-activity-visualizer-react" ] ,
54+ } ,
1855 build : {
1956 target : "esnext" ,
2057 } ,
0 commit comments