Skip to content

ncc producing faulty source maps? #1011

@tmillr

Description

@tmillr

I'm having to manually transform the output .js.map file after building because otherwise it does not work with c8. The generated .map file has invalid file paths within it that cause c8 to not work correctly producing invalid coverage reports (regardless of the output report format). The faulty paths begin with something like ../webpack:// (clearly an invalid filesystem path).

Now, I was ultimately able to get my coverage reports working correctly after a couple days of constant debugging and headaches. The solution I came up with is to manually transform the .map file post-build/post-compile in order to fix the faulty file paths myself. The faulty paths appear in the sources key of the .js.map file. You can view my temporary fix here: https://github.com/tmillr/breaking-change/blob/c432a9474cf9f5ee4a47f9945583fbb5a9869683/scripts/fix-sourcemap-sources.js#L1-L13

What I learned (I think), is that c8 uses these generated paths in the sources key of the .map file in order to retrieve the actual (pre-compile) source content from the filesystem. So, when these filesystem paths are incorrect/malformed because they begin with ../webpack://, c8 will produce inaccurate/faulty coverage reports (in my case, in my tests, it was being reported (via c8) that the compiled file was never even loaded/run, even though it was, and to make matters even worse, c8 was not making it obvious that there was any kind of error).

Context/Env

My project is a fairly standard and vanilla node project using only js (no typescript), the latest versions of all dependencies including ncc (i.e. v0.34.0), and only has a few dependencies. I'm not using any other bundlers or transpilers. Project is "type": "module" and uses es module syntax.

ncc build src/index.js -sm --no-source-map-register --license NOTICE.txt

I then mv all build outputs in dist, except for the emitted package.json, to the project root.

Sidenote: Another thing I've noticed is that ncc fails to minify my project and prints a message saying as much. This failure/message doesn't appear when I build in CI/GitHub Actions however.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreleased

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions