Skip to content

Commit 650cd95

Browse files
committed
only require webpack.ts at build time
1 parent 4b40f61 commit 650cd95

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

packages/nextjs/src/config/withSentryConfig.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { isBuild } from '../utils/isBuild';
12
import type {
23
ExportedNextConfig,
34
NextConfigFunction,
45
NextConfigObject,
56
NextConfigObjectWithSentry,
67
SentryWebpackPluginOptions,
78
} from './types';
8-
import { constructWebpackConfigFunction } from './webpack';
99

1010
/**
1111
* Add Sentry options to the config to be exported from the user's `next.config.js` file.
@@ -46,8 +46,18 @@ function getFinalConfigObject(
4646
// Remind TS that there's now no `sentry` property
4747
const userNextConfigObject = incomingUserNextConfigObject as NextConfigObject;
4848

49-
return {
50-
...userNextConfigObject,
51-
webpack: constructWebpackConfigFunction(userNextConfigObject, userSentryWebpackPluginOptions, userSentryOptions),
52-
};
49+
// In order to prevent all of our build-time code from being bundled in people's route-handling serverless functions,
50+
// we exclude `webpack.ts` and all of its dependencies from nextjs's `@vercel/nft` filetracing. We therefore need to
51+
// make sure that we only require it at build time.
52+
if (isBuild()) {
53+
// eslint-disable-next-line @typescript-eslint/no-var-requires
54+
const { constructWebpackConfigFunction } = require('./webpack');
55+
return {
56+
...userNextConfigObject,
57+
webpack: constructWebpackConfigFunction(userNextConfigObject, userSentryWebpackPluginOptions, userSentryOptions),
58+
};
59+
}
60+
61+
// At runtime, we just return the user's config untouched.
62+
return userNextConfigObject;
5363
}

0 commit comments

Comments
 (0)