Skip to content

fix(pnp): always initialize the ESM loader when enabled#3667

Merged
arcanis merged 9 commits into
masterfrom
merceyz/fix/pnp-esm
Nov 10, 2021
Merged

fix(pnp): always initialize the ESM loader when enabled#3667
arcanis merged 9 commits into
masterfrom
merceyz/fix/pnp-esm

Conversation

@merceyz

@merceyz merceyz commented Oct 28, 2021

Copy link
Copy Markdown
Member

What's the problem this PR addresses?

Dynamic imports doesn't work in commonjs files when the entrypoint is also a commonjs module.

Fixes #3671
Fixes #3687
Fixes PnP support in the Babel repo (cc @nicolo-ribaudo)
Fixes (part of) the failing Angular e2e test

How did you fix it?

Checklist

  • I have read the Contributing Guide.
  • 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.

@merceyz merceyz added the esm label Oct 28, 2021
@merceyz merceyz force-pushed the merceyz/fix/pnp-esm branch 2 times, most recently from 170b32a to c920355 Compare October 29, 2021 20:33
);

test(
`it should always set default as module.exports when importing a commonjs file`,

@arcanis arcanis Nov 3, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Quick note: it's worth adding a (in-PR) comment when tests are removed, explaining why they aren't relevant anymore (were they bugged?) 😃

@merceyz merceyz Nov 3, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I documented it in the commit that removed them

@timmywil

Copy link
Copy Markdown

Could this be released to canary?

@merceyz

merceyz commented Nov 16, 2021

Copy link
Copy Markdown
Member Author

Sure, running it now https://github.com/yarnpkg/berry/actions/runs/1468300994

Alternatively you can get it from sources

yarn set version from sources

@teohhanhui

Copy link
Copy Markdown

@merceyz

merceyz commented Nov 17, 2021

Copy link
Copy Markdown
Member Author

The publish to the registry failed but set version... doesn't use the registry so it doesn't matter.

yarn set version canary

@kherock

kherock commented Nov 18, 2021

Copy link
Copy Markdown
Contributor

The extensionless file workaround for nodejs/node#33226 in this PR doesn't work when I'm attempting to load an entrypoint with an arbitrary file extension that's intended to be parsed by a require hook like babel-register. I have a local package that loads an entrypoint with a .ts extension that should normally load as CJS.

Are there any gotchas to renaming the ``: and `.js`: cases to the default: case? I expect .ts to load as CJS when the package doesn't declare "type": "module". This assumption might change once .mts exists, but for now defaulting to the package type feels like the most correct behavior.

@merceyz

merceyz commented Nov 21, 2021

Copy link
Copy Markdown
Member Author

Could you open a seperate issue to track that?

Are there any gotchas to renaming the ``: and .js: cases to the default: case?

We don't want to deviate from how Node behaves more than we have to so we could only do that for the entrypoint

@tavoyne

tavoyne commented Jan 29, 2022

Copy link
Copy Markdown
Contributor

I'm experiencing an analogous issue that this PR doesn't seem to be fixing.

I'm trying to use the @mdx-js/loader@2.0.0-rc.2 webpack loader. In the package's entry point (it's a .cjs file), there's a dynamic import of an ES module that causes the following error:

node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/blackjelly/code/blog-3/.yarn/__virtual__/@mdx-js-loader-virtual-a537165eb1/0/cache/@mdx-js-loader-npm-2.0.0-rc.2-eb4487e27d-5637b8d92c.zip/node_modules/@mdx-js/loader/lib/index.js' imported from /Users/blackjelly/code/blog-3/.yarn/__virtual__/@mdx-js-loader-virtual-a537165eb1/0/cache/@mdx-js-loader-npm-2.0.0-rc.2-eb4487e27d-5637b8d92c.zip/node_modules/@mdx-js/loader/index.cjs

Which setting Yarn's version from sources or using canary doesn't fix.

@merceyz

merceyz commented Jan 29, 2022

Copy link
Copy Markdown
Member Author

Please open a bug report with a reproduction

@yarnpkg yarnpkg locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug?]: PnP fails to resolve dynamic require from CJS [Bug?]: cannot import chai from a module using PNP

6 participants