Skip to content

Commit 07b9d2e

Browse files
authored
fix(nextjs): Match folder paths with trailing separator (#8615)
1 parent 511ba83 commit 07b9d2e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export function constructWebpackConfigFunction(
110110
appDirPath = path.join(projectDir, 'src', 'app');
111111
}
112112

113-
const apiRoutesPath = path.join(pagesDirPath, 'api', '/');
113+
const apiRoutesPath = path.join(pagesDirPath, 'api');
114114

115115
const middlewareJsPath = path.join(pagesDirPath, '..', 'middleware.js');
116116
const middlewareTsPath = path.join(pagesDirPath, '..', 'middleware.ts');
@@ -148,8 +148,8 @@ export function constructWebpackConfigFunction(
148148
test: resourcePath => {
149149
const normalizedAbsoluteResourcePath = normalizeLoaderResourcePath(resourcePath);
150150
return (
151-
normalizedAbsoluteResourcePath.startsWith(pagesDirPath) &&
152-
!normalizedAbsoluteResourcePath.startsWith(apiRoutesPath) &&
151+
normalizedAbsoluteResourcePath.startsWith(pagesDirPath + path.sep) &&
152+
!normalizedAbsoluteResourcePath.startsWith(apiRoutesPath + path.sep) &&
153153
dotPrefixedPageExtensions.some(ext => normalizedAbsoluteResourcePath.endsWith(ext))
154154
);
155155
},
@@ -193,7 +193,7 @@ export function constructWebpackConfigFunction(
193193
test: resourcePath => {
194194
const normalizedAbsoluteResourcePath = normalizeLoaderResourcePath(resourcePath);
195195
return (
196-
normalizedAbsoluteResourcePath.startsWith(apiRoutesPath) &&
196+
normalizedAbsoluteResourcePath.startsWith(apiRoutesPath + path.sep) &&
197197
dotPrefixedPageExtensions.some(ext => normalizedAbsoluteResourcePath.endsWith(ext))
198198
);
199199
},
@@ -238,7 +238,7 @@ export function constructWebpackConfigFunction(
238238
// ".js, .jsx, or .tsx file extensions can be used for Pages"
239239
// https://beta.nextjs.org/docs/routing/pages-and-layouts#pages:~:text=.js%2C%20.jsx%2C%20or%20.tsx%20file%20extensions%20can%20be%20used%20for%20Pages.
240240
return (
241-
normalizedAbsoluteResourcePath.startsWith(appDirPath) &&
241+
normalizedAbsoluteResourcePath.startsWith(appDirPath + path.sep) &&
242242
!!normalizedAbsoluteResourcePath.match(/[\\/](page|layout|loading|head|not-found)\.(js|jsx|tsx)$/)
243243
);
244244
},

0 commit comments

Comments
 (0)