diff --git a/packages/next/build/webpack/loaders/next-flight-client-loader.ts b/packages/next/build/webpack/loaders/next-flight-client-loader.ts index 6106ae699207752..b3f99dedcc6585d 100644 --- a/packages/next/build/webpack/loaders/next-flight-client-loader.ts +++ b/packages/next/build/webpack/loaders/next-flight-client-loader.ts @@ -87,9 +87,11 @@ async function parseModuleInfo( } = node // exports.xxx = xxx if ( + left && + left.object && left.type === 'MemberExpression' && - left?.object.type === 'Identifier' && - left.object?.value === 'exports' + left.object.type === 'Identifier' && + left.object.value === 'exports' ) { addExportNames(names, left.property) } diff --git a/test/integration/react-streaming-and-server-components/app/components/random-module-instance.client.js b/test/integration/react-streaming-and-server-components/app/components/random-module-instance.client.js new file mode 100644 index 000000000000000..02696a05605b209 --- /dev/null +++ b/test/integration/react-streaming-and-server-components/app/components/random-module-instance.client.js @@ -0,0 +1,5 @@ +import { random } from 'random-module-instance' + +export default function () { + return `node_modules instance from .client.js:${random}` +} diff --git a/test/integration/react-streaming-and-server-components/app/node_modules/random-module-instance/index.js b/test/integration/react-streaming-and-server-components/app/node_modules/random-module-instance/index.js new file mode 100644 index 000000000000000..228bc8856d8f524 --- /dev/null +++ b/test/integration/react-streaming-and-server-components/app/node_modules/random-module-instance/index.js @@ -0,0 +1 @@ +exports.random = ~~(Math.random() * 1e5) diff --git a/test/integration/react-streaming-and-server-components/app/node_modules/random-module-instance/package.json b/test/integration/react-streaming-and-server-components/app/node_modules/random-module-instance/package.json new file mode 100644 index 000000000000000..4a42016896d246a --- /dev/null +++ b/test/integration/react-streaming-and-server-components/app/node_modules/random-module-instance/package.json @@ -0,0 +1,4 @@ +{ + "name": "random-module-instance", + "main": "./index.js" +} diff --git a/test/integration/react-streaming-and-server-components/app/pages/shared.server.js b/test/integration/react-streaming-and-server-components/app/pages/shared.server.js index 4bb1e2c534ffafb..1377c464df648dd 100644 --- a/test/integration/react-streaming-and-server-components/app/pages/shared.server.js +++ b/test/integration/react-streaming-and-server-components/app/pages/shared.server.js @@ -1,13 +1,22 @@ import ClientFromDirect from '../components/client.client' import ClientFromShared from '../components/shared' import SharedFromClient from '../components/shared.client' +import Random from '../components/random-module-instance.client' + +import { random } from 'random-module-instance' export default function Page() { // All three client components should be rendered correctly, but only // shared component is a server component, and another is a client component. // These two shared components should be created as two module instances. + + // It's expected to have hydration mismatch here. return ( -
+
+ +
+ {`node_modules instance from .server.js:` + random} +

diff --git a/test/integration/react-streaming-and-server-components/test/rsc.js b/test/integration/react-streaming-and-server-components/test/rsc.js index 1085b7526219c28..767c0543bc286f8 100644 --- a/test/integration/react-streaming-and-server-components/test/rsc.js +++ b/test/integration/react-streaming-and-server-components/test/rsc.js @@ -64,6 +64,15 @@ export default function (context, { runtime, env }) { expect(sharedServerModule[0][1]).toBe(sharedServerModule[1][1]) expect(sharedClientModule[0][1]).toBe(sharedClientModule[1][1]) expect(sharedServerModule[0][1]).not.toBe(sharedClientModule[0][1]) + + // Should import 2 module instances for node_modules too. + const modFromClient = main.match( + /node_modules instance from \.client\.js:(\d+)/ + ) + const modFromServer = main.match( + /node_modules instance from \.server\.js:(\d+)/ + ) + expect(modFromClient[1]).not.toBe(modFromServer[1]) }) it('should support next/link in server components', async () => {