Skip to content

Commit c29caa8

Browse files
author
Luca Forstner
authored
fix(nextjs): Don't match files called middleware in node_modules (getsentry#9686)
1 parent 84937a6 commit c29caa8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ export function constructWebpackConfigFunction(
172172
);
173173
};
174174

175+
const possibleMiddlewareLocations = ['js', 'jsx', 'ts', 'tsx'].map(middlewareFileEnding => {
176+
return path.join(middlewareLocationFolder, `middleware.${middlewareFileEnding}`);
177+
});
175178
const isMiddlewareResource = (resourcePath: string): boolean => {
176179
const normalizedAbsoluteResourcePath = normalizeLoaderResourcePath(resourcePath);
177-
return (
178-
normalizedAbsoluteResourcePath.startsWith(middlewareLocationFolder + path.sep) &&
179-
!!normalizedAbsoluteResourcePath.match(/[\\/]middleware\.(js|jsx|ts|tsx)$/)
180-
);
180+
return possibleMiddlewareLocations.includes(normalizedAbsoluteResourcePath);
181181
};
182182

183183
const isServerComponentResource = (resourcePath: string): boolean => {

0 commit comments

Comments
 (0)