Skip to content

Commit 80d2fcc

Browse files
committed
exclude build-time files
1 parent 9e6fd1a commit 80d2fcc

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/* eslint-disable max-lines */
2-
import { getSentryRelease } from '@sentry/node';
2+
import { deepReadDirSync, getSentryRelease } from '@sentry/node';
33
import { arrayify, dropUndefinedKeys, escapeStringForRegex, logger, stringMatchesSomePattern } from '@sentry/utils';
44
import { default as SentryWebpackPlugin } from '@sentry/webpack-plugin';
55
import * as chalk from 'chalk';
66
import * as fs from 'fs';
77
import * as path from 'path';
8+
import { WebpackPluginInstance } from 'webpack';
89

910
import {
1011
BuildContext,
@@ -100,6 +101,28 @@ export function constructWebpackConfigFunction(
100101
],
101102
});
102103
}
104+
105+
// Prevent `@vercel/nft` (which nextjs uses to determine which files are needed when packaging up a lambda) from
106+
// including any of our build-time code or dependencies. (Otherwise it'll include files like this one and even the
107+
// entirety of rollup and sucrase.)
108+
const nftPlugin = newConfig.plugins?.find((plugin: WebpackPluginInstance) => {
109+
const proto = Object.getPrototypeOf(plugin) as WebpackPluginInstance;
110+
return proto.constructor.name === 'TraceEntryPointsPlugin';
111+
}) as WebpackPluginInstance & { excludeFiles: string[] };
112+
if (nftPlugin) {
113+
const nextjsPackageRoot = path.dirname(require.resolve('@sentry/nextjs'));
114+
const nextjsPackageConfigDir = path.join(nextjsPackageRoot, 'config');
115+
const excludedNextjsPackageFiles = deepReadDirSync(nextjsPackageConfigDir).map(file =>
116+
path.join(nextjsPackageConfigDir, file),
117+
);
118+
119+
nftPlugin.excludeFiles.push(...excludedNextjsPackageFiles);
120+
} else {
121+
__DEBUG_BUILD__ &&
122+
logger.warn(
123+
'Unable to exclude Sentry build-time helpers from nft files. Could not find `TraceEntryPointsPlugin`.',
124+
);
125+
}
103126
}
104127

105128
// The SDK uses syntax (ES6 and ES6+ features like object spread) which isn't supported by older browsers. For users

0 commit comments

Comments
 (0)