create-react-app: CRA 2 breaks the use of mapbox-gl: Uncaught ReferenceError: _typeof is not defined

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® Core™ 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 temp-mapbox
cd temp-mapbox
yarn add react-map-gl
yarn start

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. https://github.com/mapbox/mapbox-gl-js/issues/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. https://github.com/mapbox/mapbox-gl-js/issues/4348#issuecomment-339755919

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!

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 23 (12 by maintainers)

Most upvoted comments

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.

This fix is out in 2.0.4! Please upgrade and test.

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

@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.

deleted node_modules? 😃