Skip to content

Commit 52901ad

Browse files
committed
fix
1 parent 6402bec commit 52901ad

File tree

7 files changed

+35
-31
lines changed

7 files changed

+35
-31
lines changed

packages/next/src/build/webpack-config.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -926,13 +926,13 @@ export default async function getBaseWebpackConfig(
926926
: []
927927

928928
const swcLoaderForMiddlewareLayer = useSWCLoader
929-
? getSwcLoader({ hasServerComponents: false, bundleTarget: 'server' })
929+
? getSwcLoader({ hasServerComponents: false, bundleTarget: 'default' })
930930
: // When using Babel, we will have to use SWC to do the optimization
931931
// for middleware to tree shake the unused default optimized imports like "next/server".
932932
// This will cause some performance overhead but
933933
// acceptable as Babel will not be recommended.
934934
[
935-
getSwcLoader({ hasServerComponents: false, bundleTarget: 'server' }),
935+
getSwcLoader({ hasServerComponents: false, bundleTarget: 'default' }),
936936
getBabelLoader(),
937937
]
938938

@@ -980,7 +980,7 @@ export default async function getBaseWebpackConfig(
980980
loader: 'next-swc-loader',
981981
options: {
982982
...getSwcLoader().options,
983-
bundleTarget: 'server',
983+
bundleTarget: 'default',
984984
hasServerComponents: false,
985985
},
986986
}
@@ -1965,6 +1965,7 @@ export default async function getBaseWebpackConfig(
19651965
'next-flight-action-entry-loader',
19661966
'next-flight-client-module-loader',
19671967
'noop-loader',
1968+
'empty-loader',
19681969
'next-middleware-loader',
19691970
'next-edge-function-loader',
19701971
'next-edge-app-route-loader',
@@ -2117,7 +2118,7 @@ export default async function getBaseWebpackConfig(
21172118
/^client-only$/,
21182119
/next[\\/]dist[\\/]compiled[\\/]client-only[\\/]error/,
21192120
],
2120-
loader: 'noop-loader',
2121+
loader: 'empty-loader',
21212122
issuerLayer: {
21222123
or: WEBPACK_LAYERS.GROUP.nonClientServerTarget,
21232124
},
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import type { webpack } from 'next/dist/compiled/webpack/webpack'
2+
3+
const EmptyLoader: webpack.LoaderDefinitionFunction = () => 'export default {}'
4+
export default EmptyLoader

test/e2e/module-layer/index.test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ createNextDescribe(
55
{
66
files: __dirname,
77
},
8-
({ next, isNextDev, isNextStart }) => {
8+
({ next, isNextStart }) => {
99
function runTests() {
1010
it('should render routes marked with restriction marks without errors', async () => {
1111
const routes = [
@@ -21,6 +21,7 @@ createNextDescribe(
2121
// pages/api
2222
'/api/hello',
2323
'/api/hello-edge',
24+
'/api/mixed',
2425
]
2526

2627
for (const route of routes) {
@@ -61,39 +62,38 @@ createNextDescribe(
6162

6263
describe('no server-only in server targets', () => {
6364
const middlewareFile = 'middleware.js'
64-
const pagesApiFile = 'pages/api/hello.js'
65+
// const pagesApiFile = 'pages/api/hello.js'
6566
let middlewareContent = ''
66-
let pagesApiContent = ''
67+
// let pagesApiContent = ''
6768

6869
beforeAll(async () => {
6970
await next.stop()
7071

7172
middlewareContent = await next.readFile(middlewareFile)
73+
// pagesApiContent = await next.readFile(pagesApiFile)
74+
7275
await next.patchFile(
7376
middlewareFile,
7477
middlewareContent
7578
.replace("import 'server-only'", "// import 'server-only'")
76-
.replace(
77-
"// import { sharedComponentValue } from './lib/mixed-lib'",
78-
"import { sharedComponentValue } from './lib/mixed-lib'"
79-
)
80-
)
81-
pagesApiContent = await next.readFile(pagesApiFile)
82-
await next.patchFile(
83-
pagesApiFile,
84-
pagesApiContent
85-
.replace("import 'server-only'", "// import 'server-only'")
86-
.replace(
87-
"// import { sharedComponentValue } from '../../lib/mixed-lib'",
88-
"import { sharedComponentValue } from '../../lib/mixed-lib'"
89-
)
79+
.replace("// import './lib/mixed-lib'", "import './lib/mixed-lib'")
9080
)
9181

82+
// await next.patchFile(
83+
// pagesApiFile,
84+
// pagesApiContent
85+
// .replace("import 'server-only'", "// import 'server-only'")
86+
// .replace(
87+
// "// import '../../lib/mixed-lib'",
88+
// "import '../../lib/mixed-lib'"
89+
// )
90+
// )
91+
9292
await next.start()
9393
})
9494
afterAll(async () => {
9595
await next.patchFile(middlewareFile, middlewareContent)
96-
await next.patchFile(pagesApiFile, pagesApiContent)
96+
// await next.patchFile(pagesApiFile, pagesApiContent)
9797
})
9898
runTests()
9999
})
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import 'server-only'
22
import { NextResponse } from 'next/server'
3-
// import { sharedComponentValue } from './lib/mixed-lib'
3+
// import './lib/mixed-lib'
44

55
export function middleware(request) {
6-
// Just make sure variable `sharedComponentValue` won't be eliminated
7-
if (request.pathname === 'this-is-a-path-that-wont-trigger') {
8-
return NextResponse.redirect('/' + sharedComponentValue)
9-
}
10-
116
return NextResponse.next()
127
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'server-only'
22

33
export default function handler() {
4-
return new Response('api/hello-edge.js:' + sharedComponentValue)
4+
return new Response('pages/api/hello-edge.js:')
55
}
66

77
export const runtime = 'edge'
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'server-only'
2-
// import { sharedComponentValue } from '../../lib/mixed-lib'
32

43
export default function handler(req, res) {
5-
return res.send('api/hello.js:' + sharedComponentValue)
4+
return res.send('pages/api/hello.js:')
65
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import '../../lib/mixed-lib'
2+
3+
export default function handler(req, res) {
4+
return res.send('pages/api/mixed.js:')
5+
}

0 commit comments

Comments
 (0)