-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Uncaught ReferenceError: _createClass is not defined (after transpiling with Babel) #10173
Comments
Thanks for the report! The root cause of this is that after our switch from a ES5 bundle to a ES6 one, Babel transpilation of the bundle breaks it due to the way we set up worker code. We're investigating ways to address this, but the current workaround is to configure your app to exempt |
Thanks for the explanation!
|
I just wanted to add that I get the same behavior with an Angular project which of course is also using webpack for transpilation. FWIW I'm also targeting ES6 and that doesn't make a difference. I don't know if this helps as it is not the direct issue, but its something I found when I was wondering if the problem was my fault: The other issue I noticed in attempting the 2.0.0 version is that I got the error suggesting that AMD or CommonJS scripts cause bailout issues; which in Angular-speak means I had to add it to my allowedCommonJsDependencies entry in the angular.json file. I'm wondering if there is a CommonJS or other dependency that needs to be loaded and/or checked for being loaded ahead of mapbox-gl functionality being called? Is anything filename dependent? That is when the code gets moved to a shared chunk file with a funky long alphanumeric name. is something looking for mapbox-gl.js and not loading it? These questions are based on a read of the link above. I also ran across this question on stack overflow and the marked answer is interesting: Admittedly I'm not knowledgeable enough on the setups of everything y'all are using or the consequences of the changing to ES5->ES6, except for what the previous link mentions about different babel versions which wrap scripts in CommJS wrappers. Hopefully there is something helpful here. If you put up a potential fix I can update my project to use via npm I will be happy to try again and report any findings. |
@mourner @arindam1993 I can't manage to make this work without the fix. The map part of my library will be on hold until it's done. Do you guys have an approximate ETA for this? |
@antoinealej still investigating this as it's quite a tricky problem, but we expect to have a fix as a part of v2.0.1 in about a week or two, and will also try to find a definite workaround early next week. |
I have the same issue after upgrading to 2.0 in an app created with "Create react app". It breaks when loading the map, but it works afterwards while dynamically changing the styles. Rolling back to v1 for the time being. |
Same issue here |
I have the same issue with React with Create React App. Works great in dev, but does not work with a production build. Repros with as little as instantiating the map:
with the following error:
|
Same behavior observed in a gatsbyjs app, maps work fine when running |
Heads up that so far we've landed #10219 to make it easier to fix (will be included in the v2.0.1 patch release), and are also adding a docs section on transpilation issues: https://github.com/mapbox/mapbox-gl-js-docs/pull/461 |
It looks like the fixes will require customizing our bundlers. Is there any fix planned that will help those of us using Create React App with no access to our bundler? |
One workaround for Create React App, where the bundler config is not configurable, is to use Webpack's inline loader syntax. First, install the worker-loader package ( // eslint-disable-next-line import/no-webpack-loader-syntax
mapboxgl.workerClass = require('worker-loader!mapbox-gl/dist/mapbox-gl-csp-worker').default; You probably need the |
Hello! Are there any workarounds for Create React App integration? |
Taking @LeVadim's comment a bit further after reflecting on it a couple of days - I think you all will have a lot of issues filed on you on a constant basis if this doesn't "just work" with create-react-app given its very high level of popularity. |
I tried this an get the same error. |
@momolarson this workaround works for me in a React app. I added the worker-loader package ( |
@rsippl - wow! thanks for the tip! I had added it before my imports (specifically AFTER the mapbox-gl import). I really appreciate that! |
@mtuanp exclude !== ignore and there are some issues getting this to work in Gatsby. Anybody using it yet? |
You should follow this solution #10173 (comment) |
@nicowernli Go here instead as I've outlined everything as a consumer of the lib. Browserlists isn't a solution. see here |
this worked for me. thank you |
I have a project that I haven't touched in months. Now when I open the project, I get this error (even though I haven't upgraded or changed anything). I can't figure out why -- maybe because my browser has updated? So far none of the fixes have helped me resolve this issue which is pretty frustrating since this project had a working map but now it does not, even though the project and project dependencies haven't changed. |
I had the same problem and I solved using // @ts-ignore before import line, like this: and vuala the map appears. I hope this works for you |
I'm working on a |
It works for me, Thanks!!! By the way, The above setting which changes the workerClass is not working well for me, and the console display: UnhandledPromiseRejectionWarning: TypeError: The 'compilation' argument must be an instance of Compilation I guess it is related to the version of webpack. |
Downgrading react-map-gl to version 5.3.10 solved my problem. Thanks |
this link appears to be dead, can you share a working link please? |
Please is there any fix on this for create react app? none of the suggestions above worked for me, I am way behind in my project because of this. I am very frustrated about this. |
For anyone who is still struggling with this in a create-react-app environment. My solution was to fix all the warnings related to maplibre thrown by npm start. |
Please can you share how you went about that? Because in my case the map
goes blank.
…On Wed, 14 Dec 2022 at 2:38 PM, sypyyy ***@***.***> wrote:
For anyone who is still struggling with this in a create-react-app
environment. My solution was to fix all the warnings related to maplibre
thrown by npm start.
I tried with all the solutions above and none of them works for me. And
just when all hope seem lost, I tried to fix the compile warnings thrown
and it worked!!!!!!!!!!!!!!!!!!!!!!
|
For anyone who arrives here like I did, I will share what worked for me. I am using DeckGL, maplibregl, CRA, and react-map-gl. This is what worked for me: visgl/react-map-gl#1284 . Specifically, I added the following to my browserlists configuration in package.json: ">0.2%, not dead, not ie 11, not chrome < 51, not safari < 10, not android < 51" |
Solution for this issue that worked for me without changing the browserlists: In Map.js component:
in eslintrc: |
|
Could you please explain what you mean by this exactly? I'm having the same issue. |
Wait, so this is still an issue using Mapbox's current build? |
Solution is here: https://github.com/maplibre/maplibre-gl-js/discussions/675 This part of your package.json file should look like this:
|
--- 🔴 EDIT from a gl-js maintainer 🔴 ----
We've just opened #10565 do go over some of the decisions of why we moved to ES6, and also summarizing the solutions that everyone has contributed in this thread.
Would love for the discussion to be continued there. 🙇🏽
--- 🔴 END EDIT🔴-----
mapbox-gl-js version: 2.0.0
browser: Google Chrome Version 87.0.4280.67 (Official Build) (x86_64)
Steps to Trigger Behaviour
I'm trying to build a library of Vue components and one component uses mapbox-gl.
I created a test project to showcase the issue.
When I build and use it I have an error message saying:
Link to Demonstration
https://gitlab.com/antoinealej/test-lib-mapbox-gl-build
Expected Behaviour
Display the map over a beige background
Actual Behaviour
Only displays the beige background container
The text was updated successfully, but these errors were encountered: