[0.4.6] Incorrect lines when used with babel-loader
(options.sourceMap
)
#110
Comments
@gabaum10 we get source map from |
@evilebottnawi I'm having a hard time installing the beta. When I add it via npm directly from the git+https://github.com/webpack-contrib/uglifyjs-webpack-plugin.git#v1.0.0-beta.2, it's just adding a folder in the node_modules directory with nothing I can reference and am getting the following error:
It doesn't seem to generate a /dist/ directory with the index.js file. Do I need to manually run a build before it's usable in my webpack config? |
@gabaum10 |
Thanks! I just confirmed the issue is still happening with the beta version. I'll make a test repo now and see if I can reproduce it in a simple test case. |
@gabaum10 great! |
@evilebottnawi So I tried to create a simple project with approximately the same configuration as our main web project, but the maps seem to work correctly here. https://github.com/gabaum10/webpack-uglifyjs-sourcemap-test Obviously our main project is many orders of magnitude more complex. Is there anything that we could be doing that might make the line numbers get thrown off? Maybe importing something incorrectly? We are trying to migrate our old style RequireJS implementation to use es6 imports and commonJS requires. We mostly use es6 imports, but a few requires mixed in where developers were not diligent. Could the mixing and matching be the problem? I tried to simulate that in my test repo, but it didn't seem to impact it. I can't believe that this hasn't been an issue anywhere before. Should I perhaps take this to Stackoverflow? |
babel-loader
(options.sourceMap
)
Holy crap. There was something with webpack@3.5.3 that was causing the issue. I updated to 3.5.5, the latest and everything just started magically working. Yeesh. So if anyone has this problem, update to 3.5.5 for the next 3 days before that becomes outdated. :) |
Crap, scratch that. I had the plugin disabled. Man, my brain is really fizzling... |
@gabaum10 tomorrow i investigate this, tired, thanks! |
I have a theory that I have been mulling over. In our main web project we have a good number of circular dependencies. I have disabled the circular dependency plugin because I wasn't seeing any runtime errors. Perhaps that might be causing the issues I'm seeing? I'll will try to resolve the circular dep tomorrow and report back if that helped. Is there a precedence for that causing issues while using uglify? |
There's no bug here. Better minification negatively impacts debugability. As statements are combined, reordered, folded and removed it stands to reason that many breakpoints will no longer work in the debugger. If you're willing to accept a few percent larger minified code size just set the uglify options:
you'll get the results you seek. See: mishoo/UglifyJS#2213 (comment) |
I just used the debugger in FireFox for the first time in ages (FF55) and I'm happy to report it can step through fully uglified code (compress + mangle) with source maps - unlike Chrome 60. Firefox has a superior debugging experience. Chrome has to pick up their game. |
I'll try that in a bit and it all might be well and good, but we can't exactly tell people to use Firefox so we can get proper error logs. This goes beyond debuggability but actually limits how useful stack traces are. |
Unfortunately, that doesn't seem to have helped. The line numbers are still messed up. @kzc just to confirm, I initialized the plugin like so:
That seems to spit out mangled, uncompressed code, I think. Back to my theory, could circular deps potentially cause these issues? |
@gabaum10 Maybe 😄 Test repo contain problem? |
My source map comments above were just about uglify itself. Webpack appears to have longstanding issues with source maps on Chrome: |
Well, the source maps work perfectly fine when I turn the uglify plugin off. I don't think it's directly because of chrome and sourcemaps. I've resolved my circular deps and things still seem wonky, so that rules out that theory... |
Could this be an issue with dead code? I had a theory that it might be the case as we have a very large codebase with a bunch of legacy code littered throughout and probably have a bunch of dead code. The experiment: I found an entry point with very little dependencies and bundled that alone. The source maps were seemingly perfect. I then added a massive dead code block and then tried the source maps and set a bunch of breakpoints in the dead code block and it somehow broke on the breakpoints I set. See image below: Those lines never should have been hit. |
Ok, quick update. @jpgilchrist may be on to something. I setup eslint for our project and starred the ever so enjoyable process of fixing all 200k issues. Some of these issues were none other than dead code. After finishing about 70%, I ran the production build with uglify and am happy to report an almost perfect source map. Let me finish up fixing all those issues and I will report back and close this issue as needed. I really think the line number discrepancy was because of the dead code in all our terrible legacy code. |
Great news, after cleaning up all our code, the source map lines are now perfectly aligned! Phew, that was an adventure, but I hope this finding helps someone in the future. |
@gabaum10 Congratulations! |
@evilebottnawi but that seems like it's a pretty significant issue. Webpack touts its ability to perform tree shaking. The fact that the existence of dead code causes issues in the generation of source maps is rather disconcerting. With webpack it's relatively common practice to specify something like if (SOMETHING_DEFINED_BY_DEFINE_PLUGIN) {
doSomething();
} If that Is this a webpack issue, an uglifyjs issue, or is it an uglifyjs-webpack-plugin issue? @gabaum10 I'm not sure this should be closed quite yet. |
@jpgilchrist need investigate this, maybe related webpack/webpack#2145 or webpack/webpack#3165, or maybe problem(s) inside |
Alright, well let's investigate further then. |
it is not a issue on uglifyjs-webpack-plugin. |
here is a demo. maybe webpack sourcemap mix bug |
@xiachaoxulu do you create issue in |
yes. but it maybe babel-loader's issue. i am crazy |
@xiachaoxulu can you link the issue you made in the webpack repo here? |
Webpack: 3.5.3
uglifyjs: webpack-plugin: 0.4.6
babel-core: 6.25.0
babel-loader: 7.1.1
webpack.config.js:
Notice this screenshot from the chrome debugger. There are lines that should quite obviously be able to be debuggable that you can't set breakpoints on. This is from the sourcemap for the file.
Using that combination of tools, my source maps lines are completely out of whack. I can't set breakpoints where I obviously should be able to, and errors are being reported at completely wrong line numbers. If I remove either the uglify plugin or the babel loader, the source maps are rendered correctly. I figured I would start with this plugin before moving on.
I'm at my wits end here. Is this a known issue?
The text was updated successfully, but these errors were encountered: