@@ -5,10 +5,8 @@ import {defineConfig} from 'vite';
55import react from '@vitejs/plugin-react' ;
66import wasm from 'vite-plugin-wasm' ;
77import { resolve , dirname } from 'path' ;
8- import { createRequire } from 'module' ;
98import { fileURLToPath } from 'url' ;
109
11- const _require = createRequire ( import . meta. url ) ;
1210const _dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
1311
1412// @turf /rewind ESM entry only has `export default rewind` (no named export), but
@@ -27,75 +25,11 @@ const turfRewindPlugin = {
2725 }
2826} ;
2927
30- // @hubble .gl/react was compiled with esbuild targeting Node, using isNodeMode=1 in
31- // its __toESM helper. With isNodeMode=1, __toESM ALWAYS sets .default to the entire
32- // require() result regardless of the module's __esModule flag:
33- //
34- // var import_react_map_gl = __toESM(require("react-map-gl"), 1)
35- // → import_react_map_gl.default = entire_exports_object ← "got: object"
36- //
37- // This was fine when react-map-gl/7 and @deck.gl/react/8 each did
38- // `module.exports = TheComponent` (the require result was the component directly).
39- // Modern versions wrap everything: `module.exports = __toCommonJS({Map, ...})`.
40- //
41- // Vite plugins (resolveId/load) are NOT invoked for nested node_modules during
42- // esbuild pre-bundling. @hubble.gl/react has its own node_modules/react-map-gl@7.1.9,
43- // so the Vite plugin chain is bypassed for that resolution entirely.
44- //
45- // Fix: use a native esbuild plugin (optimizeDeps.esbuildOptions.plugins). These run
46- // inside esbuild itself and intercept every require() call, including from nested
47- // node_modules. The shim sets module.exports = <component> so that
48- // __toESM(require("pkg"), 1).default === <component> ✓
49- const reactMapGlCjsPath = _require . resolve ( 'react-map-gl/mapbox' ) ;
50- const deckGlReactCjsPath = _require . resolve ( '@deck.gl/react' ) ;
51-
52- function makeHubbleInteropShim ( getComponent : string , cjsPath : string ) : string {
53- return [
54- '"use strict";' ,
55- `const _m = require(${ JSON . stringify ( cjsPath ) } );` ,
56- `const Comp = ${ getComponent } ;` ,
57- // Copy all named exports onto Comp so useControl, DeckGL etc. remain accessible
58- // as properties (for callers using import_pkg.useControl or import_pkg.DeckGL).
59- 'Object.assign(Comp, _m);' ,
60- // Ensure Comp.default === Comp so _interopRequireDefault also works.
61- 'Comp.default = Comp;' ,
62- // module.exports = Comp means __commonJS wrapper returns Comp directly,
63- // so __toESM(require("pkg"), isNodeMode=1).default === Comp (a React forwardRef).
64- 'module.exports = Comp;'
65- ] . join ( '\n' ) ;
66- }
67-
68- // This is an esbuild-level plugin, NOT a Vite plugin.
69- // It must be placed in optimizeDeps.esbuildOptions.plugins to run during pre-bundling.
70- const hubbleGlInteropEsbuildPlugin = {
71- name : 'hubble-gl-cjs-interop' ,
72- setup ( build : any ) {
73- build . onResolve ( { filter : / ^ r e a c t - m a p - g l $ / } , ( ) => ( {
74- path : 'react-map-gl-shim' ,
75- namespace : 'hubble-gl-interop'
76- } ) ) ;
77- build . onResolve ( { filter : / ^ @ d e c k \. g l \/ r e a c t $ / } , ( ) => ( {
78- path : 'deck-gl-react-shim' ,
79- namespace : 'hubble-gl-interop'
80- } ) ) ;
81- build . onLoad ( { filter : / .* / , namespace : 'hubble-gl-interop' } , ( args : any ) => {
82- if ( args . path === 'react-map-gl-shim' ) {
83- return {
84- contents : makeHubbleInteropShim ( '_m.Map' , reactMapGlCjsPath ) ,
85- loader : 'js' ,
86- resolveDir : _dirname
87- } ;
88- }
89- if ( args . path === 'deck-gl-react-shim' ) {
90- return {
91- contents : makeHubbleInteropShim ( '_m.DeckGL' , deckGlReactCjsPath ) ,
92- loader : 'js' ,
93- resolveDir : _dirname
94- } ;
95- }
96- } ) ;
97- }
98- } ;
28+ // @hubble .gl/react now ships proper ESM (no longer compiled with isNodeMode=1).
29+ // The old CJS shim for react-map-gl and @deck.gl/react is no longer needed and
30+ // was causing a double-init of luma.gl: the shim used require() which pulled in
31+ // the CJS chain (@deck.gl/core -> @luma.gl/* CJS) while kepler.gl ESM pulled in
32+ // the ESM luma.gl, resulting in two separate Luma class instances in the bundle.
9933
10034// All @kepler .gl/* packages and their pure-CJS transitive dependencies.
10135// These must be pre-bundled by esbuild so Vite serves them as ESM rather than
@@ -219,6 +153,8 @@ export default defineConfig({
219153 '@math.gl/sun' ,
220154 '@math.gl/types' ,
221155 '@math.gl/web-mercator' ,
156+ '@hubble.gl/core' ,
157+ '@hubble.gl/react' ,
222158 'thrift' ,
223159 ...nodePolyfillDeps
224160 ]
@@ -233,8 +169,7 @@ export default defineConfig({
233169 exclude : [ 'parquet-wasm' , '@loaders.gl/parquet' ] ,
234170 include : [ ...keplerPackages , 'apache-arrow' , ...loadersCjsDeps , ...nodePolyfillDeps ] ,
235171 esbuildOptions : {
236- target : 'es2020' ,
237- plugins : [ hubbleGlInteropEsbuildPlugin ]
172+ target : 'es2020'
238173 }
239174 }
240175} ) ;
0 commit comments