Skip to content

Invalid line numbers #36

Closed
Closed

Description

@dhbaird

Stack traces are producing incorrect line numbers.

Steps to reproduce:

uglifysanity.js:

console.log('1');
goober();
console.log('2');
console.log('3');
console.log('4');
console.log('5');

Then run it through uglify:

uglifyjs -c -m -o uglifysanity.min.js \
         --source-map uglifysanity.min.js.map \
         uglifysanity.js

Finally, test it in node:

require('source-map-support').install();
require('./uglifysanity.min');

And it produces this output:

.../uglifysanity.min.js:1
exports, require, module, __filename, __dirname) { console.log("1"),goober(),c
                                                                    ^

.../uglifysanity.js:6
console.log('5');                     <---------- Wrong line!
^
ReferenceError: goober is not defined
    at Object.<anonymous> (.../uglifysanity.js:6:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at [stdin]:5:1
    at Object.<anonymous> ([stdin]-wrapper:6:22)
    at Module._compile (module.js:456:26)

Expect this instead:

.../uglifysanity.js:2
goober();
^

In Chrome, this seems to work fine. Just not working in Node.js. I'm using source-map-support@0.2.8 and uglify-js@2.4.15 and Node v0.10.25.

Activity

  1. julien-f commented on Apr 7, 2015

    @julien-f
    Collaborator

    It seems that this error is due to the header Node prepends in memory to the module:

    (function (exports, require, module, __filename, __dirname) { 

    This header impacts the column number in the stacktrace which must be corrected before mapping the position.

  2. julien-f commented on Apr 20, 2015

    @julien-f
    Collaborator

    @evanw Any updates on this?

  3. pspeter3 commented on May 16, 2015

    @pspeter3
    Contributor

    The problem here is that sometimes we want to remove the header and sometimes we want to maintain it. It is unclear when one is preferable.

  4. added a commit that references this issue on May 16, 2015
  5. added a commit that references this issue on May 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions