Skip to content

Make yarn work inside a workspace with "type": "module"#1354

Merged
arcanis merged 3 commits intoyarnpkg:masterfrom
bgotink:feature/module-workspace
May 14, 2020
Merged

Make yarn work inside a workspace with "type": "module"#1354
arcanis merged 3 commits intoyarnpkg:masterfrom
bgotink:feature/module-workspace

Conversation

@bgotink
Copy link
Copy Markdown
Member

@bgotink bgotink commented May 13, 2020

What's the problem this PR addresses?

Yarn doesn't work inside workspaces with "type": "module".

Fixes #985

How did you fix it?

Switch the yarn releases from .js to .cjs file extension. This marks the file as always being CommonJS, regardless of the surrounding workspace's type.

The same change should be done in yarn v1, given that a lot of people will keep using v1 as global yarn for the foreseeable future.

Future work?

Right now we store the PnP file as .pnp.js for regular workspaces, and as .pnp.cjs for workspaces marked type=module. There are some downsides to this approach:

  • This leads to quite a bit of if-checks in yarn itself (generation fo the pnp file, the NODE_OPTIONS environment variable and pnpify).
  • If there are external tools that depend on the .pnp.js file, they will need to also check for .pnp.cjs.
  • This makes switching from one to the other more painful than it needs to be, because you need to run yarn && yarn pnpify --sdk and reload your IDE.

Always using .pnp.cjs removes these downsides.

bgotink and others added 3 commits May 13, 2020 21:01
This ensures the file will correctly load in all workspaces,
regardless of their "type".

Fixes yarnpkg#985
Right now the command can fail if the temporary folder contains
a package.json with `"type": "module"`.
@arcanis arcanis merged commit ce439e1 into yarnpkg:master May 14, 2020
@bgotink bgotink deleted the feature/module-workspace branch May 14, 2020 15:54
arcanis pushed a commit to yarnpkg/yarn that referenced this pull request May 25, 2020
This improves the experience of working with yarn
in workspaces that are marked as "type": "module"
in the package.json file.

This change has also been applied in yarn 2, see yarnpkg/berry#1354
arcanis pushed a commit to yarnpkg/yarn that referenced this pull request Aug 27, 2020
This improves the experience of working with yarn
in workspaces that are marked as "type": "module"
in the package.json file.

This change has also been applied in yarn 2, see yarnpkg/berry#1354
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

Successfully merging this pull request may close these issues.

[Bug] Yarn Nightly and "type": "module" fail to work

2 participants