Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: d.m_ is not a function after upgrading to @sentry/ember 7.100.1 #10566

Closed
3 tasks done
rohitpaulk opened this issue Feb 7, 2024 · 19 comments · Fixed by #11026
Closed
3 tasks done

TypeError: d.m_ is not a function after upgrading to @sentry/ember 7.100.1 #10566

rohitpaulk opened this issue Feb 7, 2024 · 19 comments · Fixed by #11026
Labels
Package: ember Issues related to the Sentry Ember SDK Type: Bug

Comments

@rohitpaulk
Copy link

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/ember

SDK Version

7.100.1

Framework Version

7.100.1

Link to Sentry event

https://codecrafters.sentry.io/issues/4953498292/?project=5922961&query=is%3Aunresolved&referrer=issue-stream&statsPeriod=24h&stream_index=0

SDK Setup

Sentry.init({
    autoSessionTracking: true,
    dsn: config.environment === 'production' ? sentryDSN : '',
    environment: config.environment,
    tracesSampleRate: 0.01,
});

Steps to Reproduce

Load any page with Sentry enabled.

Expected Result

No errors in console

Actual Result

Errors are present in the console.

Screenshot 2024-02-07 at 23 58 35 Screenshot 2024-02-07 at 23 55 24 Screenshot 2024-02-07 at 23 58 46
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 2 Feb 7, 2024
@github-actions github-actions bot added the Package: ember Issues related to the Sentry Ember SDK label Feb 7, 2024
@mydea
Copy link
Member

mydea commented Feb 8, 2024

Hey, can you double check that all @sentry/xxx packages you have installed have the same/correct version? This smells to me like there may be an outdated dependency somewhere that is being picked up, possibly, as this method was added in an recent version.

@rohitpaulk
Copy link
Author

@mydea from the looks of it everything does seem to have the correct version:

The only entry in package.json is @sentry/ember, I looked in package-lock.json and found these:

Screenshot 2024-02-08 at 11 34 42

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 2 Feb 8, 2024
@AbhiPrasad
Copy link
Member

This should be exported:

export * from '@sentry/browser';

startBrowserTracingPageLoadSpan,

If you do

import * as Sentry from '@sentry/ember';

console.log(Sentry.startBrowserTracingPageLoadSpan);

what gets emitted?

@mike-engel
Copy link

I'm having the same issue here. Here's the output with the log:

Screenshot 2024-02-27 at 12 05 35

I'm on ^7.102.1 for all dependencies

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 2 Feb 27, 2024
@mydea
Copy link
Member

mydea commented Feb 27, 2024

Did you try this:

import * as Sentry from '@sentry/ember';

console.log(Sentry.startBrowserTracingPageLoadSpan);

Can you let us know what you see there?

@mike-engel
Copy link

@mydea That's what my screenshot is showing. Here's the first 5 lines of our sentry config file. For that screenshot, I just added the console.log line.

import * as Sentry from '@sentry/ember';
import { Event, EventHint, Breadcrumb } from '@sentry/types';
import { httpClientIntegration, extraErrorDataIntegration } from '@sentry/integrations';

console.log(Sentry.startBrowserTracingPageLoadSpan);

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 2 Feb 27, 2024
@mydea
Copy link
Member

mydea commented Feb 27, 2024

Ah, sorry, I didn't understand that, thank you!

OK, so this is not about this method but about something else... Some questions:

  • Can you enable source maps for the build - or alternatively, enable minification + source maps in dev mode and see if you get the same error there?
  • Maybe the problem is that it is minifying something that it shouldn't - although not really sure why/how this should be happening...

@mike-engel
Copy link

mike-engel commented Feb 29, 2024

@mydea here's what it looks like with sourcemaps loaded:

Screenshot 2024-02-29 at 11 11 04

And here's the source of the error:

Screenshot 2024-02-29 at 11 12 41


I'm wondering now if this has to do with tree shaking and the function is being removed? We using embroider now with all compile-time static analysis features turned on. If I pause execution at that line, Sentry is populated with functions, though probably not all the ones expected:

Screenshot 2024-02-29 at 11 21 40

If I stringify them all, this is what I get:

{
  "$e": "function m(){const e=(0,o.Gd)();for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];if(2===n.length){const[t,i]=n;return t?e.withScope((()=>(e.getStackTop().scope=t,i(t)))):e.withScope(i)}return e.withScope(n[0])}",
  "Tb": "function l(e,t){return(0,o.Gd)().captureException(e,(0,s.U0)(t))}",
  "cg": "function w(){arguments.length>0&&void 0!==arguments[0]&&arguments[0]?y():v()}",
  "e": "function p(e){(0,o.Gd)().configureScope(e)}",
  "eN": "function u(e,t){return(0,o.Gd)().captureEvent(e,t)}",
  "nZ": "function g(){return(0,o.Gd)().getScope()}",
  "n_": "function d(e,t){(0,o.Gd)().addBreadcrumb(e,t)}",
  "s3": "function b(){return(0,o.Gd)().getClient()}",
  "sU": "function h(e,t){(0,o.Gd)().setExtra(e,t)}",
  "uT": "function c(e,t){const n=\"string\"==typeof t?t:void 0,i=\"string\"!=typeof t?{captureContext:t}:void 0;return(0,o.Gd)().captureMessage(e,n,i)}",
  "yj": "function f(e){const t=b(),n=(0,o.aF)(),s=g(),{release:l,environment:c=r.J}=t&&t.getOptions()||{},{userAgent:u}=i.GLOBAL_OBJ.navigator||{},p=(0,a.Hv)({release:l,environment:c,user:s.getUser()||n.getUser(),...u&&{userAgent:u},...e}),d=n.getSession();return d&&\"ok\"===d.status&&(0,a.CT)(d,{status:\"exited\"}),y(),n.setSession(p),s.setSession(p),p}"
}

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 2 Feb 29, 2024
@mydea
Copy link
Member

mydea commented Mar 1, 2024

Hmm, so a few things immediately jump to mind there:

  1. why are there so few things there on Sentry?
  2. That leads me to 2: it seems to be overly aggressively tree shaking away stuff... I'll try to import stuff directly instead of using namespace import, maybe that's the problem, let's see!

@mydea
Copy link
Member

mydea commented Mar 1, 2024

Actually, maybe the problem is that it thinks this should be lazy loaded/imported - will try to put up a fix!

mydea added a commit that referenced this issue Mar 1, 2024
…issue (#10885)

Let's see if this actually fixes this issue:
#10566 🤔 Maybe the
internal bundler is thrown off by the fact that we lazy load browser
tracing further below, and only includes certain things in `Sentry` on
top, not sure...
AbhiPrasad pushed a commit that referenced this issue Mar 7, 2024
…issue (#10885)

Let's see if this actually fixes this issue:
#10566 🤔 Maybe the
internal bundler is thrown off by the fact that we lazy load browser
tracing further below, and only includes certain things in `Sentry` on
top, not sure...
@AbhiPrasad
Copy link
Member

We released https://github.com/getsentry/sentry-javascript/releases/tag/7.106.0 which may fix this - please give it a try and let us know!

@mike-engel
Copy link

mike-engel commented Mar 11, 2024

Unfortunately this doesn't seem to fix the issue for us (line with the breakpoint is the line with the error):

image image

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 2 Mar 11, 2024
@mydea
Copy link
Member

mydea commented Mar 11, 2024

Hmm, damn!

The problem seems to be that it is minifying and tree shaking this function (?) away, incorrectly 🤔 But I don't understand why, sadly.

Could you share your ember build config?

@mike-engel
Copy link

mike-engel commented Mar 11, 2024

Here's a slightly minified output:

const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const { Webpack } = require('@embroider/webpack');
const Funnel = require('broccoli-funnel');
const MergeTrees = require('broccoli-merge-trees');
const { WatchedDir } = require('broccoli-source');
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const PostProcessPlugin = require('./lib/embed-script-build/lib/post-process');

const environment = process.env.EMBER_ENV;
const cioEnvironment = process.env.CIO_ENV ?? 'development';
const isProduction = environment === 'production';
const skipFingerprint = process.env.SKIP_FINGERPRINT === 'true';
const forceFingerprint = process.env.FORCE_FINGERPRINT === 'true';
const publicAssetUrl = process.env.PUBLIC_ASSET_URL ?? null;

module.exports = function (defaults) {
  let appTree = new WatchedDir('app');

  // https://github.com/embroider-build/embroider/issues/758#issuecomment-983059421
  // workaround for .ts files in the mirage directories being ignored
  if (environment !== 'production') {
    appTree = new MergeTrees([
      appTree,
      new Funnel(new WatchedDir('mirage'), {
        destDir: 'mirage',
      }),
    ]);
  }

  let app = new EmberApp(defaults, {
    trees: { app: appTree },

    babel: {
      plugins: [require.resolve('ember-auto-import/babel-plugin')],
      sourceMaps: isProduction ? 'inline' : false,
    },
    autoImport: {
      watchDependencies: [
        '@customerio/fly-components',
        '@customerio/pluma-components',
        '@customerio/encompass',
        '@customerio/carta',
        '@customerio/carta-visualized',
        '@customerio/magic-html',
        '@customerio/marshaled-preview',
        '@customerio/process-conditional-comments',
        '@customerio/source-htmlparser2',
        '@customerio/event-emitter',
        '@customerio/hydra-nav-state',
        '@customerio/hydra-pluma-state',
        '@customerio/hydra-ember-test-helpers',
      ],
      forbidEval: true,
      webpack: {
        module: {
          rules: [
            // required for monaco-editor module bundling
            {
              test: /\.ttf$/i,
              use: ['file-loader'],
            },
          ],
        },
      },
    },

    sourcemaps: {
      enabled: environment !== 'test',
      extensions: ['js'],
    },

    minifyCSS: { enabled: false },

    'ember-cli-terser': {
      enabled: isProduction,

      terser: {
        compress: true,
      },
    },

    tests: process.env.EMBER_CLI_TEST_COMMAND || !isProduction,
    hinting: process.env.EMBER_CLI_TEST_COMMAND || !isProduction,

    fingerprint: {
      extensions: ['js', 'extcss', 'css', 'png', 'jpg', 'jpeg', 'gif', 'ico', 'eot', 'svg', 'ttf', 'woff', 'mp3'],
      enabled: (isProduction && !skipFingerprint) || forceFingerprint,
    },

    // third-party package configs
  });

  // various app.import calls

  let countryFlags = new Funnel('node_modules/flagpack', {
    srcDir: 'flags/4x3/',
    include: ['*.*'],
    destDir: '/assets/images/flags',
  });

  return require('@embroider/compat').compatBuild(app, Webpack, {
    extraPublicTrees: [countryFlags],
    staticAddonTestSupportTrees: true,
    staticAddonTrees: true,
    staticHelpers: true,
    staticModifiers: true,
    staticComponents: true,
    staticEmberSource: true,
    splitAtRoutes: ['internal-tools'],
    packagerOptions: {
      cssLoaderOptions: {
        import: false,
      },

      webpackConfig: {
        devtool: 'source-map',

        stats: {
          errorDetails: true,
        },

        plugins: [
          new PostProcessPlugin(app),
          new MiniCssExtractPlugin({
            filename: `assets/chunk.[chunkhash].css`,
            chunkFilename: `assets/chunk.[chunkhash].css`,
          }),
        ],

        output: {
          // Keep the output path of assets the same originally (without this,
          // all static assets are output at the root)
          // https://stackoverflow.com/a/68902490/12679717
          assetModuleFilename: (pathData) => {
            let filenameFormat = isProduction ? '[name].[contenthash][ext][query]' : '[name][ext][query]';
            let filepath = path.dirname(pathData.filename);

            // rename some ".css" assets,
            // saved as "app/assets/styles/*.extcss" to avoid default Embroider processing,
            // back to ".css" in the dist output:
            if ((pathData.filename ?? '').endsWith('.extcss')) {
              filenameFormat = isProduction ? '[name].[contenthash].css[query]' : '[name].css[query]';
            }

            return `${filepath}/${filenameFormat}`;
          },
        },

        module: {
          rules: [
            {
              test: /\.(extcss|png|jpg|jpeg|gif|ico|eot|svg|ttf|woff|mp3)$/i,
              type: 'asset/resource',
            },
            {
              test: /\.scss$/i,
              use: [
                MiniCssExtractPlugin.loader,
                'css-loader',
                {
                  loader: 'postcss-loader',
                  options: {
                    postcssOptions: {
                      config: './postcss.config.js',
                    },
                  },
                },
                {
                  loader: 'sass-loader',
                  options: {
                    sassOptions: {
                      implementation: require('sass'),
                      includePaths: [
                        'node_modules/@customerio/fly-components/app/styles',
                        'node_modules/ember-power-select/app/styles',
                        'node_modules/ember-basic-dropdown/app/styles',
                      ],
                    },
                  },
                },
              ],
            },
          ],
        },
      },
    },
  });
};

@mydea
Copy link
Member

mydea commented Mar 11, 2024

Thank you, I was able to reproduce this locally. Still no idea why it is doing that, but this PR fixed the issue for me locally, at least: #11026

mydea added a commit that referenced this issue Mar 11, 2024
It seems that this is tree shaken weirdly through the async await
import, for some reason. Maybe we can overall refactor this to instead
use build time flags (instead of async import) but I'll look into this
separately, possibly.

I was able to reproduce this with a small local app, and this seemed to
fix it.

Closes #10566
@mike-engel
Copy link

Thanks for taking a look and for the fix @mydea! Looking forward to the v7 release with this!

@AbhiPrasad
Copy link
Member

@mike-engel
Copy link

Thanks for the heads up @AbhiPrasad! Looks like this fixes it 😄

@mydea
Copy link
Member

mydea commented Mar 15, 2024

Great to hear that! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: ember Issues related to the Sentry Ember SDK Type: Bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants