Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix package resolution issue in app dir #43349

Merged
merged 2 commits into from Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -379,23 +379,14 @@ export class FlightClientEntryPlugin {
compilation.moduleGraph.getResolvedModule(dependencyToFilter)
if (!mod) return

// Keep client imports as simple
// native or installed js module: -> raw request, e.g. next/head
// client js or css: -> user request
const rawRequest = mod.rawRequest
// Request could be undefined or ''
if (!rawRequest) return

const isCSS = regexCSS.test(rawRequest)
const isLocal =
!isCSS &&
!rawRequest.startsWith('.') &&
!rawRequest.startsWith('/') &&
!rawRequest.startsWith(APP_DIR_ALIAS)

const modRequest: string | undefined = isLocal
? rawRequest
: mod.resourceResolveData?.path + mod.resourceResolveData?.query

// We have to always use the resolved request here to make sure the
// server and client are using the same module path (required by RSC), as
// the server compiler and client compiler have different resolve configs.
const modRequest: string | undefined =
mod.resourceResolveData?.path + mod.resourceResolveData?.query

// Ensure module is not walked again if it's already been visited
if (!visitedBySegment[entryRequest]) {
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/app-dir/app-external.test.ts
Expand Up @@ -147,6 +147,11 @@ describe('app dir - external dependency', () => {
).toBe('rgb(255, 0, 0)')
})

it('should use the same export type for packages in both ssr and client', async () => {
const browser = await webdriver(next.url, '/client-dep')
expect(await browser.eval(`window.document.body.innerText`)).toBe('hello')
})

it('should handle external css modules in pages', async () => {
const browser = await webdriver(next.url, '/test-pages')

Expand Down
9 changes: 9 additions & 0 deletions test/e2e/app-dir/app-external/app/client-dep/page.js
@@ -0,0 +1,9 @@
import Foo from 'client-module'

export default function Index() {
return (
<div>
<Foo />
</div>
)
}
@@ -0,0 +1,3 @@
'use client'

module.exports = () => 'hello'
@@ -0,0 +1,3 @@
'use client'

export default () => 'hello'
@@ -0,0 +1,5 @@
{
"name": "client-module",
"main": "index.js",
"module": "index.mjs"
}