question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

comparisons compression option in uglifyjs webpack prod config breaks on react-mapbox-gl

See original GitHub issue

Can you reproduce the problem with latest npm?

Yes (including npm 5).

Description

There seems to be an incompatibility between CRA 1.0+ and the react-mapbox-gl component. This bug was not present before CRA 1.0, and only shows up in production mode, which makes me think it’s a webpack 2.0 related issue.

Expected behavior

See https://github.com/davidascher/mapbox-repro-bug for a minimal test case (single component render – works in development mode, doesn’t work in production mode)

Actual behavior

In production mode (yarn build + serve -s build) , the map doesn’t show and there’s an incomprehensible traceback (as it’s minified).

Environment

Run these commands in the project folder and fill in their results:

  1. npm ls react-scripts (if you haven’t ejected): react-scripts@1.0.6
  2. node -v: v7.9.0
  3. npm -v: 5.0.0 (but it happened with 4.x as well)

Then, specify:

  1. Operating system: OSX
  2. Browser and version: Chrome 58.0.3029.110

Reproducible Demo

Source: https://github.com/davidascher/mapbox-repro-bug

(trivial CRA repo with one dependency).

Live site showing bug: https://build-wnyrhmqiph.now.sh/

/cc @alex3165 as he is the maintainer of react-mapbox-gl AFAICT.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:19 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
jfirebaughcommented, May 29, 2017

It’s a confluence of factors:

  • A module used by mapbox-gl-js has code that checks for the presence of global using typeof global !== "undefined". At the point where global is used, there’s no outer context in which a variable global is defined.
  • webworkify stringifies functions to send to the worker. This is risky, but is the only known solution for bundling worker code that:
    • Doesn’t require loading a second source file from the server
    • Doesn’t duplicate code that’s used in both worker and main thread
  • Something in create-react-app setup wraps mapbox-gl-js in function (global) { ... }.
  • Uglify decides to mangle the resulting global and transform the resulting typeof g !== "undefined" to void 0 !== g. Together, this produces broken code when the stringified function is executed outside of the function (g) { ... } wrapper.

Because of this confluence, it’s likely to be one of those situations where the maintainers of each of the individual components involved insist that what their code does is perfectly valid, and it’s the other stuff that’s making invalid assumptions and must be fixed. At the risk of doing so myself, I would say the bug is in webpack: it provides no mechanism for a package to indicate what its build/packaging/bundling requirements are. If we, the authors of mapbox-gl-js, could put something in package.json indicating “don’t mess with this code, it’s already been bundled and minified in the way that it needs to be; redundant wrapping, bundling, and mangling is likely to break it”, then issues like this wouldn’t keep cropping up.

1reaction
kzccommented, Nov 24, 2018

mapbox-gl fixed their webpack typeof global issue in https://github.com/mapbox/mapbox-gl-js/pull/6956.

The workaround in https://github.com/facebook/create-react-app/pull/2379/files is no longer needed and can be reverted.

Read more comments on GitHub >

github_iconTop Results From Across the Web

UglifyjsWebpackPlugin | webpack
This plugin uses uglify-js to minify your JavaScript. Requirements. This module requires a minimum of Node v6.9.0 and Webpack v4.0.0. Getting Started.
Read more >
webpack 4 uglifyjs not minifying and compressing
It started working after providing mode config value as production. module.exports = { // webpack config mode: process.env.NODE_ENV || ...
Read more >
UglifyjsWebpackPlugin
This plugin uses UglifyJS v3 ( uglify-es ) to minify your JavaScript. ℹ️ webpack =< v3.0.0 currently contains v0.4.6 of this plugin under...
Read more >
ECMAScript 6 Tools Awesome - DirDev.com
ES6 Lab setup - A simple setup for transpiling ES6 to ES5 using Babel or traceur with gulp and jasmine support. TypeScript -...
Read more >
Terser vs. Uglify vs. babel-minify: Comparing JavaScript ...
Terser; UglifyJS; babel-minify; Performance comparison; Configuring minifiers for React with webpack. What is minification? Minification (also ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found