Skip to content

Commit

Permalink
don't try to upload server/chunks if using webpack 4
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie committed Aug 6, 2021
1 parent 05658ac commit bad9217
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott

fix(nextjs): Differentiate between webpack 4 and 5 in server builds (#FIXME!!)

## 6.11.0

feat(nextjs): Allow for TypeScript user config files (#3847)
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type BuildContext = {
buildId: string;
dir: string;
config: Partial<NextConfigObject>;
webpack: { version: string };
};

/**
Expand Down
11 changes: 6 additions & 5 deletions packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,18 @@ function getWebpackPluginOptions(
buildContext: BuildContext,
userPluginOptions: Partial<SentryWebpackPluginOptions>,
): SentryWebpackPluginOptions {
const { isServer, dir: projectDir, buildId, dev: isDev, config: nextConfig } = buildContext;
const { isServer, dir: projectDir, buildId, dev: isDev, config: nextConfig, webpack } = buildContext;

const isWebpack5 = webpack.version.startsWith('5');
const isServerless = nextConfig.target === 'experimental-serverless-trace';
const hasSentryProperties = fs.existsSync(path.resolve(projectDir, 'sentry.properties'));

const serverInclude = isServerless
? [{ paths: ['.next/serverless/'], urlPrefix: '~/_next/serverless' }]
: [
{ paths: ['.next/server/chunks/'], urlPrefix: '~/_next/server/chunks' },
{ paths: ['.next/server/pages/'], urlPrefix: '~/_next/server/pages' },
];
: [{ paths: ['.next/server/pages/'], urlPrefix: '~/_next/server/pages' }].concat(
isWebpack5 ? [{ paths: ['.next/server/chunks/'], urlPrefix: '~/_next/server/chunks' }] : [],
);

const clientInclude = [{ paths: ['.next/static/chunks/pages'], urlPrefix: '~/_next/static/chunks/pages' }];

const defaultPluginOptions = dropUndefinedKeys({
Expand Down
19 changes: 17 additions & 2 deletions packages/nextjs/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const baseBuildContext = {
buildId: 'sItStAyLiEdOwN',
dir: '/Users/Maisey/projects/squirrelChasingSimulator',
config: { target: 'server' as const },
webpack: { version: '5.4.15' },
};
const serverBuildContext = { isServer: true, ...baseBuildContext };
const clientBuildContext = { isServer: false, ...baseBuildContext };
Expand Down Expand Up @@ -389,7 +390,21 @@ describe('Sentry webpack plugin config', () => {
]);
});

it('has the correct value when building serverful server bundles', async () => {
it('has the correct value when building serverful server bundles using webpack 4', async () => {
const finalWebpackConfig = await materializeFinalWebpackConfig({
userNextConfig,
incomingWebpackConfig: serverWebpackConfig,
incomingWebpackBuildContext: { ...serverBuildContext, webpack: { version: '4' } },
});

const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;

expect(sentryWebpackPlugin.options?.include).toEqual([
{ paths: ['.next/server/pages/'], urlPrefix: '~/_next/server/pages' },
]);
});

it('has the correct value when building serverful server bundles using webpack 5', async () => {
const finalWebpackConfig = await materializeFinalWebpackConfig({
userNextConfig,
incomingWebpackConfig: serverWebpackConfig,
Expand All @@ -399,8 +414,8 @@ describe('Sentry webpack plugin config', () => {
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;

expect(sentryWebpackPlugin.options?.include).toEqual([
{ paths: ['.next/server/chunks/'], urlPrefix: '~/_next/server/chunks' },
{ paths: ['.next/server/pages/'], urlPrefix: '~/_next/server/pages' },
{ paths: ['.next/server/chunks/'], urlPrefix: '~/_next/server/chunks' },
]);
});
});
Expand Down

0 comments on commit bad9217

Please sign in to comment.