4

I'm using require.js's build tool (through grunt-contrib-requirejs) to pack up all my code into a minified version, and I've turned on generateSourceMaps.

However, the sourcemaps require is generating are wrong. In some files, they're fine, in others they're off by a line or two; in some, they're off by as many as 17 lines. What could be going wrong?

Possibly weird things about my repo:

  • handlebars templates integrated into the build (they're precompiled, using Alex Sexton's plugin)
  • a number of shimmed files that don't include require code standard (cordova, backbone, marionette).
  • I am using r.js to concatenate files, but not to minify them. Minifying the files doesn't fix the problem (the same line errors occur).
  • in some configurations, r.js gives an error that says it cannot generate source maps if preserveLicenseComments is on. In others (when not minifying), it seems to have no problem keeping license comments. Either way, turning it off does not help correct the line numbers.
  • files that are listed later in the sourcemap header seem to have larger errors

What could be causing this, and how can I fix it?

UPDATE I've narrowed this down some: the sourcemap generator is losing a line every time it hits a line like this:

console.log('l170');     // logs as on line 170
//>>excludeStart('excludeHbsParser', pragmas.excludeHbsParser)
console.log('l172');     // logs as on line 171

I'm not precisely sure what the r.js parser is doing with these lines, but it does not seem to be accounting for them properly in the sourcemap generation.

futuraprime
  • 5,468
  • 7
  • 38
  • 58
  • Hard to tell what is going on without seeing a minimal example of the problem. I've used `generateSourceMaps` without issue in the past. – Louis Feb 25 '14 at 21:43
  • I suffer from the same issue. @futuraprime, have you found a solution? – Alek Kowalczyk Nov 08 '14 at 13:43
  • I filed an issue on it, James Burke says pragmas are deprecated and he's not interested in fixing (https://github.com/jrburke/requirejs/issues/1054). I ended up just deleting the pragmas. – futuraprime Nov 10 '14 at 20:23
  • possible duplicate of [How can I get the original line number and symbol from a sourcemap](http://stackoverflow.com/questions/25023178/how-can-i-get-the-original-line-number-and-symbol-from-a-sourcemap) – Paul Sweatte Jan 01 '15 at 05:47

1 Answers1

0

Adding to r.js config:

skipPragmas:true

Did the trick for me, not sure if this will help everyone.

https://github.com/requirejs/r.js/blob/2.2.0/build/example.build.js#L299

jcalonso
  • 1,473
  • 13
  • 19