Unverified Commit 028b8d04 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

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`
parent cb8fdc6d
...@@ -1641,7 +1641,7 @@ export default async function getBaseWebpackConfig( ...@@ -1641,7 +1641,7 @@ export default async function getBaseWebpackConfig(
return true return true
}, },
resolve: { resolve: {
conditionNames: ['react-server', 'node', 'require'], conditionNames: ['react-server', 'node', 'import', 'require'],
alias: { alias: {
// If missing the alias override here, the default alias will be used which aliases // If missing the alias override here, the default alias will be used which aliases
// react to the direct file path, not the package name. In that case the condition // react to the direct file path, not the package name. In that case the condition
...@@ -1983,9 +1983,7 @@ export default async function getBaseWebpackConfig( ...@@ -1983,9 +1983,7 @@ export default async function getBaseWebpackConfig(
new ReactLoadablePlugin({ new ReactLoadablePlugin({
filename: REACT_LOADABLE_MANIFEST, filename: REACT_LOADABLE_MANIFEST,
pagesDir, pagesDir,
runtimeAsset: true runtimeAsset: `server/${MIDDLEWARE_REACT_LOADABLE_MANIFEST}.js`,
? `server/${MIDDLEWARE_REACT_LOADABLE_MANIFEST}.js`
: undefined,
dev, dev,
}), }),
(isClient || isEdgeServer) && new DropClientPage(), (isClient || isEdgeServer) && new DropClientPage(),
......
...@@ -90,9 +90,9 @@ describe('app dir - external dependency', () => { ...@@ -90,9 +90,9 @@ describe('app dir - external dependency', () => {
containClientContent(browserClientText) containClientContent(browserClientText)
// support esm module imports on server side, and indirect imports from shared components // support esm module imports on server side, and indirect imports from shared components
expect(serverHtml).toContain('random-module-instance') expect(serverHtml).toContain('pure-esm-module')
expect(sharedHtml).toContain( expect(sharedHtml).toContain(
'node_modules instance from client module random-module-instance' 'node_modules instance from client module pure-esm-module'
) )
}) })
......
import { name } from 'random-module-instance' import { name } from 'pure-esm-module'
export default function Page() { export default function Page() {
return ( return (
......
'use client' 'use client'
import { name } from 'random-module-instance' import { name } from 'pure-esm-module'
export default function () { export default function () {
return `node_modules instance from client module ${name}` return `node_modules instance from client module ${name}`
......
export const random = ~~(Math.random() * 1e5) export const random = ~~(Math.random() * 1e5)
export const name = 'random-module-instance' export const name = 'pure-esm-module'
{
"name": "pure-esm-module",
"type": "module",
"exports": {
"import": "./index.js"
}
}
{
"name": "random-module-instance",
"type": "module",
"exports": "./index.js"
}
import ClientFromDirect from '../../components/client' import ClientFromDirect from '../../components/client'
import ClientFromShared from '../../components/shared' import ClientFromShared from '../../components/shared'
import SharedFromClient from '../../components/shared-client' import SharedFromClient from '../../components/shared-client'
// import Random from '../../components/random-module-instance'
import Bar from '../../components/bar' import Bar from '../../components/bar'
export default function Page() { export default function Page() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment