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

ncc producing faulty source maps? #1011

Closed
tmillr opened this issue Dec 2, 2022 · 1 comment · Fixed by #1122 or TheJ-Erk400/tryhackme-badge-workflow#6 · May be fixed by openziti/ziti-webhook-action#23, YoutacRandS-VA/act#1 or YoutacRandS-VA/act#4
Labels
bug Something isn't working released

Comments

@tmillr
Copy link

tmillr commented Dec 2, 2022

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.

@styfle styfle added the bug Something isn't working label Dec 3, 2022
styfle pushed a commit that referenced this issue Oct 18, 2023
- Fixes #1011 
- Fixes #1121 

The source is now in the format `webpack://[namespace]/[resourcePath]`
@github-actions
Copy link

🎉 This issue has been resolved in version 0.38.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment