rsnext/packages/next/build
Tobias Koppers 7a8da9741d
add support for esm externals (#27069)
add `experimental.esmExternals: boolean | 'loose'` config option

remove `output.environment` configuration in favor of `target`

|                          | `esmExternals: false` (default) | `esmExternals: 'loose'` | `esmExternals: true` |
| ------------------------ | ------------------------------- | ----------------------- | -------------------- |
| import cjs package       | `require()`                     | `require()`             | `require()`          |
| require cjs package      | `require()`                     | `require()`             | `require()`          |
| import mixed package     | `require()` ***                 | `import()`              | `import()`           |
| require mixed package    | `require()`                     | `require()`             | `require()`          |
| import pure esm package  | `import()`                      | `import()`              | `import()`           |
| require pure esm package | Error **                        | `import()` *            | Error **             |
| import pure cjs package  | `require()`                     | `require()`             | Resolving error      |
| require pure cjs package | `require()`                     | `require()`             | `require()`          |

cjs package: Offers only CJS implementation (may not even have an `exports` field)
mixed package: Offers CJS and ESM implementation via `exports` field
pure esm package: Only offers an ESM implementation (may not even have an `exports` field)
pure cjs package: CommonJs package that prevents importing via `exports` field when `import` is used.

`*` This case will behave a bit unexpected for now, since `require` will return a Promise. So that need to be awaited. This will be fixed once the whole next.js bundle is ESM. It didn't work at all before this PR.
`**` This is a new Error when trying to require an esm package.
`***` For mixed packages we prefer the CommonJS variant to avoid a breaking change.

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [x] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes
2021-07-10 16:49:02 +00:00
..
babel Move code shared between server/client to "shared" folder (#26734) 2021-06-30 11:43:31 +02:00
output Upgrade eslint to the latest version (#24377) 2021-04-25 18:34:36 +00:00
polyfills Upgrade to Prettier 2 (#13061) 2020-05-18 15:24:37 -04:00
profiler Added no-shadow rule to eslint (#13645) 2020-06-01 21:00:22 +00:00
webpack add support for esm externals (#27069) 2021-07-10 16:49:02 +00:00
compiler.ts Update to latest TypeScript version and de-dupe versions (#26285) 2021-06-17 17:43:25 -05:00
entries.ts Move next-server directory files to server directory (#26756) 2021-06-30 13:44:40 +02:00
generate-build-id.ts Update err.sh links to use nextjs.org/docs/messages instead (#23353) 2021-03-29 10:25:00 +02:00
index.ts Move next-server directory files to server directory (#26756) 2021-06-30 13:44:40 +02:00
is-writeable.ts Use fs.promises instead of promisify (#12026) 2020-05-02 00:10:19 -04:00
spinner.ts [Feature] Progress bar for static build (#15297) 2020-08-04 09:58:23 +02:00
utils.ts Move next-server directory files to server directory (#26756) 2021-06-30 13:44:40 +02:00
webpack-config.ts add support for esm externals (#27069) 2021-07-10 16:49:02 +00:00
write-build-id.ts Move code shared between server/client to "shared" folder (#26734) 2021-06-30 11:43:31 +02:00