Skip to content

Commit

Permalink
Document how to deal with core-js and regenerator-runtime injecti…
Browse files Browse the repository at this point in the history
…on in Yarn PnP
  • Loading branch information
wojtekmaj authored Dec 29, 2021
1 parent b31e518 commit b07b228
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/preset-env.md
Original file line number Diff line number Diff line change
Expand Up @@ -513,3 +513,25 @@ These features were behind `shippedProposals` flag in older Babel versions. They
### Ineffective browserslist queries

While `op_mini all` is a valid browserslist query, preset-env currently ignores it due to [lack of support data](https://github.com/kangax/compat-table/issues/1057) for Opera Mini.

### `core-js` and `regenerator-runtime` injections vs. Yarn PnP

Starting with version 2.0, Yarn has Plug'n'Play enabled with `pnpMode` set to `"strict"`. What this means is that Yarn won't allow modules to require packages they don't explicitly list in their own dependencies. If you happen to use `@babel/preset-env` on a module and `core-js` and/or `regenerator-runtime` ends up being injected to it depite not being listed, Yarn will throw an error similar to the following:

```
Your application tried to access core-js, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound.
ERROR in ./packages/utils/index.js 1:0-42
Module not found: Error: Can't resolve 'core-js/modules/es.array.from.js' in '/my-project/packages/utils'
(…)
Your application tried to access core-js, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound.
```

To fix this,

- set `pnpFallbackMode` to `"all`" by executing `yarn config set pnpFallbackMode all`, or:
- set:
- `config.resolve.alias["core-js"]` to `path.dirname(require.resolve("core-js"))` and
- `config.resolve.alias["regenerator-runtime"]` to `path.dirname(require.resolve("regenerator-runtime"))`


in your Webpack config.

0 comments on commit b07b228

Please sign in to comment.