Skip to content

Commit

Permalink
ref(nextjs): Remove resolve.alias treeshaking hack (#4276)
Browse files Browse the repository at this point in the history
In #3978, code was introduced to prevent node tracing integrations (mongo, postgres, etc) from appearing in the browser bundle where they don't belong. However, as part of our larger push to make our code more treeshakable, we recently changed how we export those integrations[1], making the previous workaround unnecessary.

As a bonus, this should fix a rendering issue some users were having when using the `fallback` flag.

Tested locally and on vercel.

Fixes #4090.

[1] #4204
  • Loading branch information
lobsterkatie authored and onurtemizkan committed Dec 19, 2021
1 parent c258816 commit c245c7e
Showing 1 changed file with 0 additions and 18 deletions.
18 changes: 0 additions & 18 deletions packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,6 @@ export function constructWebpackConfigFunction(
const origEntryProperty = newConfig.entry;
newConfig.entry = async () => addSentryToEntryProperty(origEntryProperty, buildContext);

// In webpack 5, you can get webpack to replace any module you'd like with an empty object, just by setting its
// `resolve.alias` value to `false`. Not much of our code is neatly separated into "things node needs" and "things
// the browser needs," but where it is, we can save ~1.6 kb in eventual bundle size by excluding code we know we
// don't need. (Normally this would only matter for the client side, but because vercel turns backend code into
// serverless functions, it's worthwhile to do it for both.)
if (buildContext.webpack.version.startsWith('5')) {
const excludedTracingDir = buildContext.isServer ? 'browser' : 'integrations/node';
newConfig.resolve = {
...newConfig.resolve,
alias: {
...newConfig.resolve?.alias,
[path.resolve(buildContext.dir, `./node_modules/@sentry/tracing/esm/${excludedTracingDir}`)]: false,
// TODO It's not clear if it will ever pull from `dist` (in testing it never does), so we may not need this.
[path.resolve(buildContext.dir, `./node_modules/@sentry/tracing/dist/${excludedTracingDir}`)]: false,
},
};
}

// Enable the Sentry plugin (which uploads source maps to Sentry when not in dev) by default
const enableWebpackPlugin = buildContext.isServer
? !userNextConfig.sentry?.disableServerWebpackPlugin
Expand Down

0 comments on commit c245c7e

Please sign in to comment.