-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
CRA 2 breaks the use of mapbox-gl: Uncaught ReferenceError: _typeof is not defined #5267
Comments
Hi @ChiefORZ, just trying to reproducing that. Used codesandbox.io, which uses the 2.0.3's create-react-app template... seems to be using it properly: https://codesandbox.io/s/kmq3vol6vo No errors there :/ |
I know added a valid token to test it ... Still works fine 👍 |
hmm, weird... can i ask you to try it out locally? for me and my colleagues it's not working at all. we re-installed all packages, tried cleaning the yarn cache... but nothing seems to help |
deleted node_modules? :) |
@ChiefORZ in terms of rendering, works... strangely, doesn't render the map but I guess that's some API's limitation? |
if you don't have any errors, that this should be that. you would need to add probably raster or vector layers etc. but that is other field :) |
This doesn’t make sense to me as an explanation. Running Uglify many times on a bundle shouldn’t cause issues. So there’s a bug here.. somewhere. Your second attempt is expected to not work. “React App Rewired” is a completely unsupported project and can cause all sorts of issues. And it’s not expected to work with 2.x. It has no active maintainer at the moment. |
@gaearon for all cra-rewired/custom-scripts users... should be point them to at least some repo that has some maintance involved? such as https://github.com/arackaf/customize-cra which currently can at least work with CRA 2? |
Yeah it would be nice to point them somewhere. |
I can confirm the issue (locally). I'm working on a company project with React-Map-Gl & React-Mapbox-Gl libraries and both are breaking since we updated to CRAv2(.0.3). Both libraries are working with CRAv1. Reference Issues: |
Have you looked into why? We need to pinpoint the reason. |
After following the trace, this seems to be an option for the failure: tl;dr: react-map-gl uses Web Workers, _typeof doesn't exist there, Possible workaround: |
Is there a way we can inject Babel helpers? I'm not familiar with this code base, can you show me when the web-worker comes into play? |
This is the weird part. I don't understand what "not getting included" means in this case. What is the code before and after running Babel? |
Appears fixed via #5278, tested with repro given in OP. This will be out in |
This fix is out in 2.0.4! Please upgrade and test. |
Dan the Man. 🤘 |
It's still worthwhile to note the way mapbox is generating their workers is very fragile and they will be prone to more breakages like this in the future. We should keep pressing for them to fix this on their end. |
@Timer hey Joe, thanks for looking into this issue! Can you elaborate on your suggestion? We set up the worker bundling this way because most of the code is shared between the main thread and the workers, and we couldn't afford duplicating that code in the bundle (it's already pretty big and e.g. embedding a worker as a string would nearly double the size). On the other hand, we also couldn't bundle workers separately because because that would be pretty confusing for users (e.g. having to specify workerURL every time, etc.). So splitting the code into three chunks (shared, main, worker) and re-bundling them to initialize workers dynamically with a blob was the only option we found that satisfied both concerns. Do you see any other options or improvements for us that would make the setup less fragile to issues like this one? |
Could you do the toString step at compile time when the package is published? |
@gaearon that's what I meant in the first point — we can't embed worker code as a string in the bundle because it would almost double the bundle size. |
in anyone tried this with Babel7? //cc @tannerlinsley |
Is this a bug report?
Yes
Did you try recovering your dependencies?
Reproducable on a newly created app
Environment
System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Binaries:
Node: 10.9.0 - /usr/local/bin/node
Yarn: 1.9.4 - /usr/local/bin/yarn
Browsers:
Chrome: 69.0.3497.100
Firefox: 61.0.2
Safari: 12.0
npmPackages:
react: ^16.5.2 => 16.5.2
react-dom: ^16.5.2 => 16.5.2
react-scripts: 2.0.3 => 2.0.3
npmGlobalPackages:
create-react-app: Not Found
First Try
https://gist.github.com/ChiefORZ/d2e77d2a3dd3703a54c8fd6fecf3f921
create-react-app 2 should work with mapbox-gl.
mapbox-gl breaks, because of
Uncaught ReferenceError: _typeof is not defined
.searching the webs for this error seems, that this error occurs when webpack uglifies the already uglified bundle and there the reference to
_typeof
gets removed.mapbox/mapbox-gl-js#4359
i think this error occurs with cra 2 again, because it got updated to use webpack 4?!
Second Try
https://gist.github.com/ChiefORZ/8a06af95cbe1acd4e1fd4d37e970e5ca
then i thought i follow the recommended solutions by excluding
mapbox-gl
from webpack build.mapbox/mapbox-gl-js#4348 (comment)
but unfortunately this is not working as well, because it doesn't use webpack_require and therefore
Uncaught ReferenceError: require is not defined
Thanks for the help!
The text was updated successfully, but these errors were encountered: