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

Source map paths are wrong #1

Closed
andrew0 opened this issue Nov 19, 2023 · 3 comments · Fixed by #2
Closed

Source map paths are wrong #1

andrew0 opened this issue Nov 19, 2023 · 3 comments · Fixed by #2

Comments

@andrew0
Copy link
Contributor

andrew0 commented Nov 19, 2023

I tried using this library but ran into some issues because the stack traces seem to be wrong. I put up a small repro here but it's really basic, just runs a script that prints a stack trace:

console.error(new Error('kaboom').stack);

When I run this with node --import=tsimp/import src/main.ts, I get this:

Error: kaboom
    at <anonymous> (/private/tmp/src/main.ts:1:15)
    at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:308:24)
    at async loadESM (node:internal/process/esm_loader:42:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)

When I build the TypeScript code with tsc and run it with node --enable-source-maps dist/main.js, I get this:

Error: kaboom
    at <anonymous> (/private/tmp/tsimp-repro/src/main.ts:1:15)
    at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:308:24)
    at async loadESM (node:internal/process/esm_loader:42:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)

With tsimp, the current directory seems to be removed from the file where the error is thrown (/private/tmp/src/main.ts when it should be /private/tmp/tsimp-repro/src/main.ts).

@andrew0
Copy link
Contributor Author

andrew0 commented Nov 20, 2023

This commit fixes the problem for me: andrew0@9164973. I would submit a PR but I'm not sure what to do with the snapshot tests, since it makes it so the source maps have an absolute path for the sourceRoot.

@andrew0 andrew0 changed the title Error stack traces are missing the current directory Source map paths are wrong Nov 20, 2023
@isaacs
Copy link
Member

isaacs commented Nov 25, 2023

Good find. I can fix up the snapshots easily enough to keep absolute paths out. (Tap will automatically prevent cwd in snapshots by default, but other paths can be a problem.)

@stuft2
Copy link

stuft2 commented Apr 24, 2024

Found this issue looking for at source map support for Node.js Test Runner.

Warning: Could not report code coverage. TypeError: Cannot read properties of undefined

This is a known limitation of the Node.js test runner. It causes the code coverage reporting to break.

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

Successfully merging a pull request may close this issue.

3 participants