From ace1080f3f0f4e0954120b699d4a3745be51140d Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Mon, 24 Jul 2023 13:21:14 +0200 Subject: [PATCH] fix(nextjs): Match folder paths with trailing separator --- packages/nextjs/src/config/webpack.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/nextjs/src/config/webpack.ts b/packages/nextjs/src/config/webpack.ts index 786ce0dfaaed..49f450bb27a4 100644 --- a/packages/nextjs/src/config/webpack.ts +++ b/packages/nextjs/src/config/webpack.ts @@ -110,7 +110,7 @@ export function constructWebpackConfigFunction( appDirPath = path.join(projectDir, 'src', 'app'); } - const apiRoutesPath = path.join(pagesDirPath, 'api', '/'); + const apiRoutesPath = path.join(pagesDirPath, 'api'); const middlewareJsPath = path.join(pagesDirPath, '..', 'middleware.js'); const middlewareTsPath = path.join(pagesDirPath, '..', 'middleware.ts'); @@ -148,8 +148,8 @@ export function constructWebpackConfigFunction( test: resourcePath => { const normalizedAbsoluteResourcePath = normalizeLoaderResourcePath(resourcePath); return ( - normalizedAbsoluteResourcePath.startsWith(pagesDirPath) && - !normalizedAbsoluteResourcePath.startsWith(apiRoutesPath) && + normalizedAbsoluteResourcePath.startsWith(pagesDirPath + path.sep) && + !normalizedAbsoluteResourcePath.startsWith(apiRoutesPath + path.sep) && dotPrefixedPageExtensions.some(ext => normalizedAbsoluteResourcePath.endsWith(ext)) ); }, @@ -193,7 +193,7 @@ export function constructWebpackConfigFunction( test: resourcePath => { const normalizedAbsoluteResourcePath = normalizeLoaderResourcePath(resourcePath); return ( - normalizedAbsoluteResourcePath.startsWith(apiRoutesPath) && + normalizedAbsoluteResourcePath.startsWith(apiRoutesPath + path.sep) && dotPrefixedPageExtensions.some(ext => normalizedAbsoluteResourcePath.endsWith(ext)) ); }, @@ -238,7 +238,7 @@ export function constructWebpackConfigFunction( // ".js, .jsx, or .tsx file extensions can be used for Pages" // 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. return ( - normalizedAbsoluteResourcePath.startsWith(appDirPath) && + normalizedAbsoluteResourcePath.startsWith(appDirPath + path.sep) && !!normalizedAbsoluteResourcePath.match(/[\\/](page|layout|loading|head|not-found)\.(js|jsx|tsx)$/) ); },