Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot assign to import "accessToken" error on Remix #1013

Open
maciej-adamus opened this issue Aug 9, 2022 · 5 comments
Open

Cannot assign to import "accessToken" error on Remix #1013

maciej-adamus opened this issue Aug 9, 2022 · 5 comments

Comments

@maciej-adamus
Copy link

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?

@rawnly
Copy link

rawnly commented Aug 10, 2022

same problem here!

@maciej-adamus
Copy link
Author

My solution was to switch to react-map-gl

@rawnly
Copy link

rawnly commented Aug 10, 2022

My solution was to switch to react-map-gl

Thanks it worked for me too

@jarrisondev
Copy link

Same problem

@lduchuy2002
Copy link

lduchuy2002 commented Dec 20, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants