Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid line numbers #36

Closed
dhbaird opened this issue Oct 30, 2014 · 3 comments
Closed

Invalid line numbers #36

dhbaird opened this issue Oct 30, 2014 · 3 comments

Comments

@dhbaird
Copy link

dhbaird commented Oct 30, 2014

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.

@julien-f
Copy link
Collaborator

julien-f commented Apr 7, 2015

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.

@julien-f
Copy link
Collaborator

@evanw Any updates on this?

@pspeter3
Copy link
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.

pspeter3 added a commit to pspeter3/node-source-map-support that referenced this issue May 16, 2015
Node adds a header of 62 characters when code is required through a
native module. If we are in node, the line number is 1 and the next file
is the native 'module.js', we subtract that header. I verified the
solution for evanw#36
by reproducing the problem. The stack trace is now:

```
user:node-source-map-support user$ node error.js
1

/Users/user/Documents/node-source-map-support/uglifysanity.js:2
goober();
^
ReferenceError: goober is not defined
at Object.<anonymous>
(/Users/user/Documents/node-source-map-support/uglifysanity.js:2:1)
```
julien-f added a commit that referenced this issue May 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants