Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,12 @@ export function constructWebpackConfigFunction(
if (userSentryOptions.autoInstrumentServerFunctions !== false) {
const pagesDir = newConfig.resolve?.alias?.['private-next-pages'] as string;

// Next.js allows users to have the `pages` folder inside a `src` folder, however "`src/pages` will be ignored
// if `pages` is present in the root directory"
// - https://nextjs.org/docs/advanced-features/src-directory
const shouldIncludeSrcDirectory = !fs.existsSync(path.resolve(projectDir, 'pages'));
const pagesDirectory = shouldIncludeSrcDirectory // We're intentionally not including slashes in the paths because we wanne let node do the path resolution for Windows
? path.resolve(projectDir, 'src', 'pages')
: path.resolve(projectDir, 'pages');

// Default page extensions per https://github.com/vercel/next.js/blob/f1dbc9260d48c7995f6c52f8fbcc65f08e627992/packages/next/server/config-shared.ts#L161
const pageExtensions = userNextConfig.pageExtensions || ['tsx', 'ts', 'jsx', 'js'];
const pageExtensionRegex = pageExtensions.map(escapeStringForRegex).join('|');

newConfig.module.rules.push({
// Nextjs allows the `pages` folder to optionally live inside a `src` folder
test: new RegExp(`^${escapeStringForRegex(pagesDirectory)}.*\\.(${pageExtensionRegex})$`),
test: new RegExp(`^${escapeStringForRegex(pagesDir)}.*\\.(${pageExtensionRegex})$`),
use: [
{
loader: path.resolve(__dirname, 'loaders/proxyLoader.js'),
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/test/config/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const serverWebpackConfig: WebpackConfigObject = {
output: { filename: '[name].js', path: '/Users/Maisey/projects/squirrelChasingSimulator/.next' },
target: 'node',
context: '/Users/Maisey/projects/squirrelChasingSimulator',
resolve: { alias: { 'private-next-pages': '/Users/Maisey/projects/squirrelChasingSimulator/pages' } },
};
export const clientWebpackConfig: WebpackConfigObject = {
entry: () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ describe('constructWebpackConfigFunction()', () => {
it("doesn't set devtool if webpack plugin is disabled", () => {
const finalNextConfig = materializeFinalNextConfig({
...exportedNextConfig,
webpack: () => ({ devtool: 'something-besides-source-map' } as any),
webpack: () =>
({
...serverWebpackConfig,
devtool: 'something-besides-source-map',
} as any),
sentry: { disableServerWebpackPlugin: true },
});
const finalWebpackConfig = finalNextConfig.webpack?.(serverWebpackConfig, serverBuildContext);
Expand Down