-
Notifications
You must be signed in to change notification settings - Fork 3
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
Missing source-map-support dependency, fails with Yarn Berry PnP #35
Comments
Getting a similar error when using Jest with this and Yarn 3.1.1:
|
This Yarn 2+ patch makes the problem go away for me, but is likely not the right thing to do. |
@cspotcode can you offer some guidance on this issue? |
@noahnu is there more detail you can offer about the error message you're getting? For example, if there is a detailed stack trace, are you able to share that? I see the error message in the issue description but I'm not sure if you've truncated a stack trace, or if the error omits the stack trace. |
The errors shown by my and @noahnu are complete. That's all you get when you use jest. If you can look at my patch, you can see how it's fixed by removing the |
I'm trying to put together a repro repository to share. |
Great, thanks for confirming. I'm going to attempt a reproduction on my end, too. If I can't reproduce, I'll share the reproduction with you so that you can fork and modify it to produce the error. |
I've started a branch with yarn 3 PnP and ts-node. If you are already making progress on your own reproduction, feel free to share that. Or, if it is easier, you can fork the branch I've created and commit modifications to your fork, then share a link here. |
Hmm, might be more of a jest issue as francisu mentioned. Confirming now |
Okay, here's the repro: https://github.com/noahnu/repro-source-map-error At least from how I was using it, it happens when you try to run jest using ts-node. I'm using a custom script which loads jest which is why we need the ts-node rather than purely rely on babel or ts-jest. This repro just tries to call jest directly though. So to be clear, I was wrong with my original comment about it having to do with |
My experience as well; thanks for doing the repro. |
What output do you get when running the reproduction? I am not seeing the error message described in your initial post. I do not see "ambiguous and unsound." |
Did you get anything bad? I did not get the ambiguous and unsound message either. Just 'cannot find module'. |
The repro I shared was somewhat incomplete. With the current setup, this is my output: λ yarn ts-node --transpile-only $(yarn bin jest)
FAIL ./index.test.ts
● Test suite failed to run
Cannot find module 'source-map-support' from '/home/noah/repos/repro-source-map-error/.yarn/cache/@cspotcode-source-map-support-npm-0.7.0-456c3ea2ce-9faddda775.zip/node_modules/@cspotcode/source-map-support'
at resolveSync (.yarn/cache/resolve-patch-bad885c6ea-c79ecaea36.zip/node_modules/resolve/lib/sync.js:111:15)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.058 s
Ran all test suites. If I first add 'source-map-support' via |
At a higher level, what's the purpose of requiring source-map-support? Should it be listed in the package.json as a peer dependency? |
I don't think we are, though. I think the opposite: jest is trying to require source-map-support, and we're redirecting to @cspotcode/source-map-support as per #23 The motivation for this is explained here: TypeStrong/ts-node#1441 It's also worth keeping in mind that jest does a lot of magic. The more magic jest has, the more likely it is to break. In this case, I see jest using this function. I don't know what it's supposed to do, but jest is using it to require source-map-support: |
Some more relevant comments here TypeStrong/ts-node#1496
Here is a link to that PR: evanw/node-source-map-support#209 |
Ah I see. I haven't reproduced my original error (ambiguous and unsound) outside of my work repo but I imagine the way the redirect is happening is causing the require to come through this repo's version of source-map-support which causes the ancestor chain to break -- hence the "ambiguous and unsound" error. I wonder if listing source-map-support as an optional peer might still make sense. At some point this week when I'm at my work computer, I can try narrow the ambiguous and unsound aspect down further. |
Here's where jest is doing the weird internal require thing: Looks like it's (a) asking node for the path to source-map-support, then it's (b) trying to |
@noahnu try clearing the jest cache (it's persistent): yarn jest --clearCache |
You might consider asking the jest folks what they're trying to do here: https://github.com/facebook/jest/blob/3a85065fe5604655e1337ffc1631f9999722c821/packages/jest-runner/src/runTest.ts#L213-L219 It seems like they're trying to require source-map-support through some custom reimplementation of node's module resolution algorithm. They do that to support their
|
Have you had any luck asking jest about the above ^ ? |
I will make an issue for them later today. |
Thanks! If you share it here, I'll be sure to subscribe and follow along. |
Any luck? |
I tried your suggestion above in repro provided by @noahnu:
The require.resolve() call is returning this:
Here is the stack trace of the original exception:
I'm not sure what's going wrong here, nor what I should ask the Jest people. If you could propose a patch that would fix the problem in the repro, I will do the leg work of making an issue with them and show how your patch fixes it. |
This looks suspicious to me.
Almost as if there's typescript generics syntax in a JS file. |
Actually, removing the '<typeof import('source-map-support')>' made it work, and I see now why. It looks like a typescript generic, but since it's in a JS file, it's a greater than and less than, and thus returning false, causing the error. So I have a working patch and repro that I can make an issue with for the Jest team. I will do that shortly. Thanks for following up with me. |
OK, let's see what they do. |
Ha ha, howdy @noahnu. Thank you all for sorting so much of this out already! I must confess that I have been putting off investigating it for months. The good news is that this issue was fixed a week ago by Jest's prolific maintainer. The bad news is that while the fix has been released in v28.0.0+, it didn't make v27, and ts-jest v27 rather sensibly pins Jest to v27. But wait, there's more good news! ts-jest 28.0.0-next.1 was released 2 days ago, and bumps Jest to v28. It works for me at Yarn 3.2.0 (but not at 3.1.0), so I think this issue can be closed if it works for others as well. Fair warning that Jest v28 has a lot of breaking changes, but I found their migration guide very helpful in my case. |
Closing since this was a jest issue, so no action required here. |
When upgrading from ts-node 10.2.0 to 10.4.0, I'm seeing a failure running a script that executes
require('ts-node').register({ transpileOnly: true })
.This is the error I see:
Using Yarn PnP 3.1.0. In yarn pnp, any package required needs to be declared in its package.json. I've tried to understand where source-map-support is required and whether it should be listed, but I had some trouble with the source code. If we want to check for the existence of the package, throwing it in a try...catch would be ideal.
The text was updated successfully, but these errors were encountered: