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

fix(pnp): esm - use correct error code when module not found #5355

Merged
merged 9 commits into from
Apr 24, 2023

Conversation

clemyan
Copy link
Member

@clemyan clemyan commented Mar 29, 2023

What's the problem this PR addresses?

This PR makes the PnP ESM loader throw with error code ERR_MODULE_NOT_FOUND (instead of MODULE_NOT_FOUND) when a request cannot be resolved.

Closes #5334

How did you fix it?

The error is thrown by the PnP CJS hook, and the ESM loader just calls the CJS hook. So we can just catch the error in the ESM loader, change the error code, and rethrow.

I am not sure about the package releases. I have marked pnp, plugin-pnp and cli as patch releases since other packages doesn't seem to use the ESM loader.

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

Copy link
Member

@merceyz merceyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clemyan
Copy link
Member Author

clemyan commented Mar 29, 2023

Added tests

Bigdawg001

This comment was marked as spam.

merceyz
merceyz previously approved these changes Apr 3, 2023
Copy link
Member

@merceyz merceyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix and the tests!

@merceyz merceyz enabled auto-merge (squash) April 24, 2023 20:44
@merceyz merceyz changed the title fix(pnp): Use correct error code when module not found fix(pnp): esm - use correct error code when module not found Apr 24, 2023
@merceyz merceyz merged commit 4927819 into yarnpkg:master Apr 24, 2023
merceyz added a commit that referenced this pull request Apr 24, 2023
* fix(pnp): Use correct error code when module not found

* test(pnp): Add tests

* Commits file updates

* fix(pnp): re-throw regardless of what the error is

---------

Co-authored-by: Kristoffer K <merceyz@users.noreply.github.com>
Co-authored-by: Maël Nison <nison.mael@gmail.com>
merceyz added a commit that referenced this pull request Apr 24, 2023
* fix(pnp): Use correct error code when module not found

* test(pnp): Add tests

* Commits file updates

* fix(pnp): re-throw regardless of what the error is

---------

Co-Authored-By: Kristoffer K <merceyz@users.noreply.github.com>
Co-Authored-By: Maël Nison <nison.mael@gmail.com>
@merceyz merceyz added the esm label Apr 25, 2023
@clemyan clemyan deleted the fix-pnp-loader-error-code branch September 6, 2023 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug?]: PnP ESM loader throw wrong error code
4 participants