-
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
Build fails when using mapbox-gl webpack 2 and UglifyJSPlugin #4359
Comments
Seeing this as well. Anyone know which version I can downgrade to, which minifies properly? |
Fixed the problem by setting |
Could this be a WebPack 2 bug? This doesn't seem to be a fault on the GL JS side. |
@mourner yeah definitely. The weird thing is that this was working about a month ago for me. I'm trying to narrow down which dependency is causing the issue. @henningko eval works for me too, but what about production? |
@stevewillard I was just happy to get a minified version out. 😐 I have opened an issue with webpack, too. It's still a gnarly workaround to get them to function together. |
Having this in production build since the end of last week, after upgrading mapbox-gl and its react wrapper. Could you please share your workaround guys? PS: Could not find any mentioning of this error message outside the context of mapbox-gl-js. |
For what it's worth, I built an app about a month ago with mapbox-gl 0.32.1 and webpack 2.2.0 and it built correctly. I just started an almost-identical project with mapbox-gl 0.33.0 and webpack 2.2.1 and I'm having the same problem described above. (Although in my case it says I tried moving mapbox-gl to its own un-minified chunk (didn't work, more problems from Webpack), but that seems like it could fix the problem. The "dist" code in the npm package is minified anyway, so I'd like to tell the uglifier to leave it alone... |
With the version numbers mentioned above, it does build properly if you add the option to not optimize comparisons:
So, it's something in that Uglify function that's wrecking Mapbox. |
@foundryspatial-duncan thank you for finding the potential source of the issue! Looks like it should be fixed upstream and there's probably nothing we can do on the GL JS side, so I'm closing the issue for now. If you submit related reports in the relevant repos, please link them here to track resolution progress! |
just add this in webpack, will be ok |
@zezhipeng solution works for me. Not a 100% sure what it does though. Does this mean |
I've been importing MapboxGL not using the default entrypoint, but rather:
It says (said?) to do that somewhere in the documentation. I remember trying noParse with the dist version and I don't think I had any luck with it. edit: I guess that's not the practice with the most recent versions of mapbox-gl. If you just import from |
This also happens when running meteor --production with Meteor version 1.4.4. |
I looked into this a bit more:
This is the type of edge case that makes Webpack a huge hassle for both library maintainers and end users, because it doesn't have a way for individual modules to indicate their bundling requirements, like browserify does. Everyone has to encounter these errors for themselves, and then google around for obscure incantations to add to their hundreds-of-lines-long webpack config. There's no way that we as library authors can package Mapbox GL JS so that it "just works" out of the box with Webpack, and in the end, everybody is frustrated. TL;DR: yet again I conclude that browserify made the right design decisions and webpack the wrong ones. |
See facebook/create-react-app#2376 (comment) and mishoo/UglifyJS#2011 (comment) for parallel analysis. In particular, from our digging, it seems to be the code that's going through
which wraps https://github.com/mapbox/mapbox-gl-js/blob/master/src/source/worker.js, but I haven't figured out what in that code or its imports is problematic. |
@mourner see in particular facebook/create-react-app#2376 (comment) -- it seems that it's either |
Problematic issue what would cause people to disable minification entirely. relates issues in other projects facebook/create-react-app#2379 sleepycat/old_usesthis@523c872 mapbox/mapbox-gl-js#4359 mishoo/UglifyJS#2011 (comment)
Getting the same issue when using |
Anybody figure out a solution to this? I tried adding mapbox to Using webpack 2.6.1 (with UglifyJsPlugin) and mapbox-gl 0.38.0 |
@Aendrew setting up the most minimal repo or gist that reproduces this with the latest versions of GL JS and Webpack/Uglify so that we have an up-to-date test case would be very helpful. |
@mourner I set up a minimal repro w/ 0.45 here: https://gist.github.com/anandthakker/6db8a871ccbbaba8afd7deeb483731ef |
@anandthakker I just used your repro and the map works fine for me. Anything I'm missing? |
@mourner Here's a more minimalist repro that reflects the issue: https://github.com/aendrew/mapbox-gl-js--issue-4359-repro I don't do anything other than instantiate Mapbox and do a build in production mode. |
A PR with a potential solution here: #6956 — let me know what you think! |
Ah, whoops -- in my gist, I think it works because of the |
@anandthakker interestingly, it still worked for me with |
Can folks here who have been affected by the issue please try out the fix in #6956 (using a build from master) and confirm that it resolves the issue for them and doesn't cause any new issues? If so we'll include it in 0.47.0 final (due out Wednesday 7/18). |
Master did not seem to fix this for me but @chriswhong's solution got me going. |
@math0ne can you provide us with a minimal test case for a |
@jfirebaugh @mourner Reiterating my comment from #6956, I tried a build from |
) * fix webpack prod mode compatibility Closes #4359 * add a comment about ignoreGlobal
Looks good for me as well with mapbox-gl 0.47.0. Congrats! |
…o have been fixed with latest release. Brilliant.
I think a similar issue is back with mapbox v2.6.1 and webpack 5 with terser, though it's weird because on prod it always fails to load but on dev it fails only about 50% of the time Need to investigate a bit more The error I'm getting is |
I've the same problem with CRA + mapbox-gl@2.6.1. It's not possible to build for production |
My workaround: module.exports = {
babel: {
loaderOptions: {
ignore: ['./node_modules/mapbox-gl/dist/mapbox-gl.js'],
}
}
}; |
mapbox-gl-js version:
0.32.1
Steps to Trigger Behavior
Set up Mapbox with webpack 2 via vuejs-template
Configuration is as follows:
Base:
https://gist.github.com/henningko/5a76d12a14e485bfc4dd62c2e50ad08e
Production:
https://gist.github.com/henningko/3387f41a55558af60205ea00bbc6b530
Mapbox is used with
import mapboxgl from 'mapbox-gl'
.Expected Behavior
Mapbox can be successfully uglified.
Actual Behavior
When building for production, UglifyJS2 has Mapbox throw a
Uncaught ReferenceError: n is not defined
.This error also occurs when using Google Closure instead of UglifyJS.
May be related to #1649 , which mainly treats webpack v1 and is closed.
Thanks for your help!
The text was updated successfully, but these errors were encountered: