I work with Angular and RequireJS. I tried to use RequireJS optimization, and now my application is not working. I am sure it's due to minification.
Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.2.0rc1/$injector/modulerr?p0=myapp&p1=Error%3…t%20(http%3A%2F%2Flocalhost%3A8080%2Fwebapp%2Fapp%2Fmain-built.js%3A4%3A10)
The error message is not very helpful to find the issue, so I was wondering how I can use the source map to pinpoint the error in the original source code. I use Chrome to debug.
Edit: Full error stacktrace
Failed to instantiate module myapp due to:
Error: [$injector:unpr] http://errors.angularjs.org/1.2.0rc1/$injector/unpr?p0=e
at Error (<anonymous>)
at http://localhost:8080/webapp/app/main-built.js:3:19581
at http://localhost:8080/webapp/app/main-built.js:3:31899
at n (http://localhost:8080/webapp/app/main-built.js:3:30540)
at Object.r [as invoke] (http://localhost:8080/webapp/app/main-built.js:3:30716)
at http://localhost:8080/webapp/app/main-built.js:3:30147
at Array.forEach (native)
at o (http://localhost:8080/webapp/app/main-built.js:3:19891)
at i (http://localhost:8080/webapp/app/main-built.js:3:29951)
at yt (http://localhost:8080/webapp/app/main-built.js:4:10
General source map error reporting js mentions a source map, and the source map URL tells us where to find the source map data (in this case, relative to the resource). The error tells us that the source map is not JSON data — so we're serving the wrong file.
A source map is a file that maps from the transformed source to the original source, enabling the browser to reconstruct the original source and present the reconstructed original in the debugger. To enable the debugger to work with a source map, you must: generate the source map.
In a sense, source maps are the decoder ring to your secret (minified) code. Using Webpack, specifying devtool: "source-map" in your Webpack config will enable source maps, and Webpack will output a sourceMappingURL directive in your final, minified file.
Here are the steps which should make it working for you:
main.js:12
.If source maps are still not working:
Make sure minified JS file contains, at the very bottom, something like:
//# sourceMappingURL=main.js.map
Make sure mapping file is being downloaded. It should be listed in "Network" section of Developer Tools as downloaded during page reload. It should look like this:
Maybe RequireJS's minification strips out the sourceMappingURL
comment from your output JS file?
Make sure that you're using uglify2
method and you've enabled generateSourceMaps
option. Here is relevant part of my requirejs
target config from Grunt:
requirejs: {
compile: {
options: {
/* some other options here */
optimize: 'uglify2',
logLevel: 0,
preserveLicenseComments: false,
generateSourceMaps: true
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With