Skip to content

Commit

Permalink
Fix export conditions in Webpack config (#46066)
Browse files Browse the repository at this point in the history
Currently the export conditions we use for certain runtime, in different
places of the config are totally random. This PR unifies them by
referring to the single constant.

Also adds `worker` as a condition of the edge runtime.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## 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`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
shuding and ijjk committed Feb 18, 2023
1 parent 7e6cc0c commit 607dd69
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,13 @@ export default async function getBaseWebpackConfig(
const mainFieldsPerCompiler: Record<typeof compilerType, string[]> = {
[COMPILER_NAMES.server]: ['main', 'module'],
[COMPILER_NAMES.client]: ['browser', 'module', 'main'],
[COMPILER_NAMES.edgeServer]: ['edge-light', 'browser', 'module', 'main'],
[COMPILER_NAMES.edgeServer]: [
'edge-light',
'worker',
'browser',
'module',
'main',
],
}

const reactDir = path.dirname(require.resolve('react/package.json'))
Expand Down Expand Up @@ -1021,7 +1027,13 @@ export default async function getBaseWebpackConfig(
}
: undefined),
mainFields: mainFieldsPerCompiler[compilerType],
...(isEdgeServer && { conditionNames: ['edge-light', 'import', 'node'] }),
...(isEdgeServer && {
conditionNames: [
...mainFieldsPerCompiler[COMPILER_NAMES.edgeServer],
'import',
'node',
],
}),
plugins: [],
}

Expand Down Expand Up @@ -1690,7 +1702,11 @@ export default async function getBaseWebpackConfig(
resolve: {
conditionNames: [
'react-server',
...(!isEdgeServer ? [] : ['edge-light']),
...mainFieldsPerCompiler[
isEdgeServer
? COMPILER_NAMES.edgeServer
: COMPILER_NAMES.server
],
'node',
'import',
'require',
Expand Down

0 comments on commit 607dd69

Please sign in to comment.