react-mapbox-gl icon indicating copy to clipboard operation
react-mapbox-gl copied to clipboard

Cannot assign to import "accessToken" error on Remix

Open maciej-adamus opened this issue 1 year ago • 5 comments

I am trying to use the library in Remix environment. When I import and use the map component, I am getting this error:

X [ERROR] Cannot assign to import "accessToken"

     node_modules/react-mapbox-gl/lib-esm/map.js:59:25:
       59 │                 MapboxGl.accessToken = accessToken;
          ╵                          ~~~~~~~~~~~
   
      Imports are immutable in JavaScript. To modify the value of this import, you must export a setter function in the imported file (e.g. "setAccessToken") and then import and call 
that function here instead.
   
   
    Build failed with 1 error:
    node_modules/react-mapbox-gl/lib-esm/map.js:59:25: ERROR: Cannot assign to import "accessToken"

Here it says that since v1.2 the accessToken can be passed as a parameter to Map constructor. Why not do it that way?

maciej-adamus avatar Aug 09 '22 10:08 maciej-adamus

same problem here!

rawnly avatar Aug 10 '22 14:08 rawnly

My solution was to switch to react-map-gl

maciej-adamus avatar Aug 10 '22 14:08 maciej-adamus

My solution was to switch to react-map-gl

Thanks it worked for me too

rawnly avatar Aug 10 '22 19:08 rawnly

Same problem

jarrisondev avatar Jan 09 '23 22:01 jarrisondev

Add this to your bundler: resolve: { alias: [{ find: /^react-mapbox-gl+$/, replacement: 'react-mapbox-gl/lib' }] }, Add this to your index.tsx file: if (typeof window !== 'undefined') { Object.getOwnPropertyDescriptor(mapboxgl, 'accessToken')?.set?.(${your token}) }

Hope this would help you

lduchuy2002 avatar Dec 20 '23 07:12 lduchuy2002