sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Investigate why terser/webpack defaults causes SDK code to break

Open AbhiPrasad opened this issue 1 year ago • 7 comments

full context in this discord thread: https://discord.com/channels/621778831602221064/1217467422932729918/1220020216336093225

Terser inlining causing issues?

AbhiPrasad avatar Mar 20 '24 15:03 AbhiPrasad

terser itself doesn't have these minify levels so I'm guessing webpack adds these

From Tim on discord

AbhiPrasad avatar Mar 20 '24 17:03 AbhiPrasad

Terser itself doesn't appear to have minify levels, all the different options are configured individually: https://github.com/terser/terser?tab=readme-ov-file#compress-options

What level option is being referred to in the webpack config? https://webpack.js.org/plugins/terser-webpack-plugin/

timfish avatar Mar 20 '24 17:03 timfish

webpack config: https://gist.github.com/tristanbes/7e2eb2f00637e908ba0fc6f703ae52ea

AbhiPrasad avatar Mar 21 '24 13:03 AbhiPrasad

Ah ok so it's the inline levels!

options: { compress: { inline: 1 } }

timfish avatar Mar 21 '24 15:03 timfish

I've added tests for both webpack 4 and 5 and backported them to the v7 branch to see if there are any failures.

We don't see any issues with the default terser config https://github.com/getsentry/sentry-javascript/pull/11257

The webpack config looks like this:

import * as path from 'path';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import TerserPlugin from 'terser-webpack-plugin';
import webpack from 'webpack';

webpack({
    entry: path.join(__dirname, 'entry.js'),
    output: {
      path: path.join(__dirname, 'build'),
      filename: 'app.js',
    },
    optimization: {
      minimize: true,
      minimizer: [new TerserPlugin()],
    },
    plugins: [new HtmlWebpackPlugin(), new webpack.EnvironmentPlugin(['E2E_TEST_DSN'])],
    mode: 'production',
  })

timfish avatar Mar 23 '24 00:03 timfish

I wonder if this may be related to https://github.com/getsentry/sentry-javascript/issues/10566 - ember uses terser under the hood 🤔 there the problem seemed to be related to tree shaking & minifying, somehow.

mydea avatar Mar 25 '24 09:03 mydea

Maybe my test cases should at least access more of the SDK API?

timfish avatar Mar 25 '24 09:03 timfish

I think this is hopefully fixed, let's close this for now.

mydea avatar Jul 04 '24 11:07 mydea