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

yarn pnp issues #241

Closed
koshic opened this issue Sep 8, 2023 · 14 comments
Closed

yarn pnp issues #241

koshic opened this issue Sep 8, 2023 · 14 comments

Comments

@koshic
Copy link
Collaborator

koshic commented Sep 8, 2023

Other scoped modules can't be mocked too. Wrong regexp?

Haven't enough time to provide unit test right now (

@iambumblehead
Copy link
Owner

iambumblehead commented Sep 8, 2023

I will be able to take a look soon

edit

reproduction repo is here: https://github.com/koshic/esmock-testing

@iambumblehead
Copy link
Owner

@koshic if you have bandwidth, would you add a failing test in a PR? ideally, the test would be added to the bottom of tests/tests-node/esmock.node.test.js

We could merge the failed-test PR right away and I could resolve the scope issue myself in a different branch.

@iambumblehead
Copy link
Owner

Haven't enough time to provide unit test right now (

Sorry I missed this not much sleep here. I'll add a test.

@iambumblehead
Copy link
Owner

iambumblehead commented Sep 8, 2023

@koshic an "@aws-sdk/client-s3" mock test is added here: #242

The test passes. Would you help me to reproduce the issue? Maybe change the tests that are there or add a new test. I don't know how to reproduce the error.

@koshic
Copy link
Collaborator Author

koshic commented Sep 8, 2023

@iambumblehead sure, but tomorrow by Moscow time ) I was hoping to be free today, but...

@iambumblehead
Copy link
Owner

@koshic no rush take your time :) https://www.youtube.com/watch?v=Lqg8_gpUm5A

@koshic
Copy link
Collaborator Author

koshic commented Sep 9, 2023

I'm here and will try to provide broken test / review other PRs

@koshic
Copy link
Collaborator Author

koshic commented Sep 10, 2023

@iambumblehead at first - thank you for creating branch and PR! My local example is very similar.

BTW, tests failed (github codespace, the same result on my local machine with node 20.6.1) after 'npm test':
image

It's a bit strange because on CI/CD both tests are passed:
image

@iambumblehead
Copy link
Owner

esmock does not support npm workspaces as mentioned in the other issue #235 (comment)

Could that be the issue?

That message is thrown when esmock cannot locate the moduleId, for example if the moduleId is found in a workspace esmock's resolver cannot lookup.

const errModuleIdNotFound = (moduleId, parent) =>
  new Error(`invalid moduleId: "${moduleId}" (used by ${parent})`)
// ...
  const moduleFileURL = resolvewith(moduleId, parent)
  if (!moduleFileURL)
    throw esmockErr.errModuleIdNotFound(moduleId, parent)

Maybe try the suggestion from tpluscode added to the wiki https://github.com/iambumblehead/esmock/wiki#call-esmock-npm-workspaces

Maybe support for workspaces should be added to the resolver.

@koshic
Copy link
Collaborator Author

koshic commented Sep 10, 2023

Yeah , thx for that workaround - root cause is switching from import.meta.resolve to resolvewithplus, which is also doesn't support Yarn PnP.

@koshic koshic closed this as completed Sep 10, 2023
@iambumblehead
Copy link
Owner

@koshic I am trying to reproduce the "invalid moduleId" error, in order to update esmock so that workarounds will not be needed. Please give advice, if you know how the error could be reproduced.

Current tests which do not show the invalid moduleId error are here

@iambumblehead iambumblehead reopened this Sep 13, 2023
@iambumblehead iambumblehead changed the title Error: invalid moduleId: "@aws-sdk/client-s3" in 2.4.1 pnpm issues Sep 13, 2023
@iambumblehead
Copy link
Owner

@koshic when this other issue is resolved #235 I'll spend time looking into this pnp issue

@iambumblehead iambumblehead changed the title pnpm issues yarn pnp issues Sep 13, 2023
@iambumblehead
Copy link
Owner

based on some investigation and on this discussion here wooorm/import-meta-resolve#10 I am going to re-close this issue

@iambumblehead
Copy link
Owner

if yarn pnp's module-resolving were refined to an npm package, other packages like esmock could use that to support pnp resolution. oh well, such a package does not exist.

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

No branches or pull requests

2 participants