node-source-map-support
node-source-map-support copied to clipboard
File path is lost when translating stack traces
When using node-source-map-support (v0.2.10) via babel-node, file paths are being lost for the files local to the package. This also occurs when I override babel's copy to [email protected]
With the file foo/bar.js:
console.trace();
console.log(new Error().stack);
When running the file via regular node, I get stack traces with full file paths:
> node foo/bar.js
Trace
at Object.<anonymous> (/babel-repro/foo/bar.js:1:71)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
at startup (node.js:117:18)
at node.js:951:3
Error
at Object.<anonymous> (/babel-repro/foo/bar.js:2:13)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
at startup (node.js:117:18)
at node.js:951:3
When running with babel-node, the path of the source file is lost:
> babel-node foo/bar.js
Trace
at Object.<anonymous> (bar.js:1:17)
at Module._compile (module.js:434:26)
at loader (/Users/ian/.nvm/versions/node/v4.1.0/lib/node_modules/babel-cli/node_modules/babel-register/lib/node.js:130:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/ian/.nvm/versions/node/v4.1.0/lib/node_modules/babel-cli/node_modules/babel-register/lib/node.js:140:7)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
at /Users/ian/.nvm/versions/node/v4.1.0/lib/node_modules/babel-cli/lib/_babel-node.js:161:27
at Object.<anonymous> (/Users/ian/.nvm/versions/node/v4.1.0/lib/node_modules/babel-cli/lib/_babel-node.js:162:7)
at Module._compile (module.js:434:26)
Error
at Object.<anonymous> (bar.js:2:13)
at Module._compile (module.js:434:26)
at loader (/Users/ian/.nvm/versions/node/v4.1.0/lib/node_modules/babel-cli/node_modules/babel-register/lib/node.js:130:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/ian/.nvm/versions/node/v4.1.0/lib/node_modules/babel-cli/node_modules/babel-register/lib/node.js:140:7)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
at /Users/ian/.nvm/versions/node/v4.1.0/lib/node_modules/babel-cli/lib/_babel-node.js:161:27
at Object.<anonymous> (/Users/ian/.nvm/versions/node/v4.1.0/lib/node_modules/babel-cli/lib/_babel-node.js:162:7)
at Module._compile (module.js:434:26)
This occurs at any directory depth; only the file's base name survives. Is there something Babel's doing incorrectly here?
For reference, Babel sets up source-map-support via babel-register
Related Babel issue: https://phabricator.babeljs.io/T6839
I have the same problem. I am just wondering why babel doesn't have correct line numbers if it is including source map support? I only added this node-source-map-support because I saw that the line numbers were wrong with -r babel-core/register…
Scratch that, the absolute paths are also gone without node-source-map-support. This must be squarely babel's fault.
You can verify this yourself by looking at ~/.babel.json, which is the babel cache. The files are missing their full path, it seems.
I am seeing a similar problem with typescript and inlineSourceMaps option. external sourceMaps works fine.
I don't think it's a source map issue. If I am not wrong it is probably generated with stripped file path. You can check it if you open it (decode it if you are using inline maps) and look at the "sources" field.
I was having the same issue and solved it by passing absolute path as "sourceFileName" directly to babel options: https://github.com/babel/babel/blob/master/packages/babel-register/src/node.js#L68-L74
@v3lbloud You are my saver! I was trying your solution some time ago but it didn't help, now I tried it again but first removed babel cache file ~/.babel.json, and it worked!
@ilearnio I am glad I could help :)