-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Unable to use react-map-gl in create-react-app #176
Comments
Looks like a webpack config issue. Take a look at the instructions in our README |
Yes indeed and I was wondering if there was a way to import I think the issue comes from the fact that
but I don't think it is a good solution... Anyway, thank you for your quick reply! |
@gauthierrodaro which files did you patch? |
@fb-owen-vandijk, Here is a zip of the patch I did. As you can see it was patched from an older version of the repo. It was only intended for testing purposes and I would not recommend this. |
@gauthierrodaro thanks! very helpful. In the end I decided to go with https://github.com/alex3165/react-mapbox-gl which I believe has the same workaround implemented. |
From other issue
I created empty project with import MapGL from 'react-map-gl' I see in browser console import mapboxgl from 'mapbox-gl'; I see warning Related: mapbox/mapbox-gl-js#1649 |
Realised that current master is 3.0.0.alpha5. While npm version is 1.8... something. Hate when this happens. Installed github versions with:
Now if I do If I do |
Per Apologies for this, not quite sure why this happens (but not totally surprised, have seen similar surprises from npm and yarn in the past). Maybe the easiest thing is just to publish a dummy 2.0.3 (@abmai).
|
This sounds strange, never saw this. does this happen if react-map-gl is the only thing you include? Can you inspect your generated bundle and search for Buffer and see if you can find anything?
That's expected. In react-map-gl v3, the dist-es6 folder has been added to support "tree-shaking" (removal of unused code from the final bundle). It should only be used by tree shaking bundlers, e.g. webpack2 and rollup. There are separate entry points specified in package.json to support autodetection of dist folder, you should not need to import a specific dist folder like this. |
Yes
I switched to webpack 2. Here is example code https://github.com/stereobooster/create-react-app-map-gl/tree/webpack-2 Now I get:
Which is: var bundleFn = arguments[3];
var sources = arguments[4];
var cache = arguments[5];
var stringify = JSON.stringify;
module.exports = function (fn, options) {
var wkey;
var cacheKeys = Object.keys(cache); |
For webpack 2 and react-map-gl 2: https://github.com/stereobooster/create-react-app-map-gl/tree/react-map-gl-2
And this is bug from Mapbox GL JS, which does not provide ES6 modules with flow-types stripped. Created ticket mapbox/mapbox-gl-js#4664 |
Correct, this has been a big headache for react-map-gl from mapbox ~0.26 forward. In fairness to mapbox, this is mainly a problem because react-map-gl v2 uses the internal mapbox Transform class (which is not exported in mapbox's pre-built file for non-browserify bundlers). There is a In react-map-gl v3 we were finally able to remove dependencies on internal mapbox files so mapbox's provided pre-built is now sufficient. (Unfortunately it still requires special webpack configuration since mapbox's package.json doesn't set the "main" entry to their pre-built). Sorry you have to get exposed to all this, one of our goals with react-map-gl v3 is to minimize these complications for new users. |
Where are you using webpack 2 here? I see no mention of webpack. Did you push your changes?
|
From yarn.lock
Exactly. This is the best part about create-react-app. It just works. And I do not believe, that there is no way to publish packages that are compatible with CRA. CRA is so good that I use it for projects without React (simply delete React dependencies). This is a breath of fresh air since Rails with it's "convention over configuration" |
Connecting dots: mapbox-gl-js will not provide ES6 module until it will not be able to switch to rollup, and it can not switch to rollup because there is no alternative for webworkify. rollup/rollup#1029. See also rollup/rollup#1320 UPD: Other way to do this would be to switch from inline-blob workers to separate file, but this is not supported by CRA at the moment facebook/create-react-app#1277 UPD2: |
@stereobooster Thanks for that interesting analysis! I've came back to looking at using react-map-gl a year on, back when I had all sorts of issues with webpack. I was semi-hopeful that this would have played nice with create-react-app by now but see it's a lot more complicated than that! 🤕 🔫 |
Update: MapboxGL now uses ES6 modules mapbox/mapbox-gl-js#6196 |
For those tracking this issue for the past few months like me, @stereobooster 's comment means react-map-gl now works with CRA without the need to eject. I just tested it with a basic CRA app and one of the examples for react-map-gl 👍 💯 |
I've added this to config-overrides.js config.resolve = {
alias: {
'mapbox-gl$': path.join(resolveApp('node_modules'), '/mapbox-gl/dist/mapbox-gl.js'),
},
}; It works in development elements all show up properly. But after build, there still being |
I have opened a PR documenting a working integration with a Typescript CRA. |
Can you share example with CRA ? |
Did someone manage to make it work in create-react-app ?
I got this error:
My component is quite simple
Thank you in advance for taking interest in this issue.
The text was updated successfully, but these errors were encountered: