Skip to content

Commit 028b8d0

Browse files
authored
Fix resolving for esm package with only exports.import condition (#42767)
Should be able to resolve `exports.import` condition for esm packages only when import them in server components Fixes: #42534 ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md`
1 parent cb8fdc6 commit 028b8d0

File tree

8 files changed

+14
-15
lines changed

8 files changed

+14
-15
lines changed

packages/next/build/webpack-config.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ export default async function getBaseWebpackConfig(
16411641
return true
16421642
},
16431643
resolve: {
1644-
conditionNames: ['react-server', 'node', 'require'],
1644+
conditionNames: ['react-server', 'node', 'import', 'require'],
16451645
alias: {
16461646
// If missing the alias override here, the default alias will be used which aliases
16471647
// react to the direct file path, not the package name. In that case the condition
@@ -1983,9 +1983,7 @@ export default async function getBaseWebpackConfig(
19831983
new ReactLoadablePlugin({
19841984
filename: REACT_LOADABLE_MANIFEST,
19851985
pagesDir,
1986-
runtimeAsset: true
1987-
? `server/${MIDDLEWARE_REACT_LOADABLE_MANIFEST}.js`
1988-
: undefined,
1986+
runtimeAsset: `server/${MIDDLEWARE_REACT_LOADABLE_MANIFEST}.js`,
19891987
dev,
19901988
}),
19911989
(isClient || isEdgeServer) && new DropClientPage(),

test/e2e/app-dir/app-external.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ describe('app dir - external dependency', () => {
9090
containClientContent(browserClientText)
9191

9292
// support esm module imports on server side, and indirect imports from shared components
93-
expect(serverHtml).toContain('random-module-instance')
93+
expect(serverHtml).toContain('pure-esm-module')
9494
expect(sharedHtml).toContain(
95-
'node_modules instance from client module random-module-instance'
95+
'node_modules instance from client module pure-esm-module'
9696
)
9797
})
9898

test/e2e/app-dir/app-external/app/external-imports/server/page.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { name } from 'random-module-instance'
1+
import { name } from 'pure-esm-module'
22

33
export default function Page() {
44
return (

test/e2e/app-dir/app-external/components/random-module-instance.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { name } from 'random-module-instance'
3+
import { name } from 'pure-esm-module'
44

55
export default function () {
66
return `node_modules instance from client module ${name}`
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export const random = ~~(Math.random() * 1e5)
2-
export const name = 'random-module-instance'
2+
export const name = 'pure-esm-module'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "pure-esm-module",
3+
"type": "module",
4+
"exports": {
5+
"import": "./index.js"
6+
}
7+
}

test/e2e/app-dir/app-external/node_modules_bak/random-module-instance/package.json

-5
This file was deleted.

test/e2e/app-dir/rsc-basic/app/shared/page.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import ClientFromDirect from '../../components/client'
22
import ClientFromShared from '../../components/shared'
33
import SharedFromClient from '../../components/shared-client'
4-
// import Random from '../../components/random-module-instance'
54
import Bar from '../../components/bar'
65

76
export default function Page() {

0 commit comments

Comments
 (0)