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

Broken @sentry/vue jest mock #6037

Closed
3 tasks done
Tofandel opened this issue Oct 25, 2022 · 4 comments · Fixed by #6043
Closed
3 tasks done

Broken @sentry/vue jest mock #6037

Tofandel opened this issue Oct 25, 2022 · 4 comments · Fixed by #6043
Assignees

Comments

@Tofandel
Copy link

Tofandel commented Oct 25, 2022

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which package are you using?

@sentry/vue

SDK Version

7.16

Framework Version

No response

Link to Sentry event

No response

Steps to Reproduce

Simply use a dynamic import

import(/* webpackChunkName: "sentry" */'@sentry/vue').then(({init}) => {
    init({
      Vue,
      environment: process.env.SERVE ? 'local' : process.env.NODE_ENV,
      dsn: process.env.VUE_APP_SENTRY_DSN,
    })
});

Or

import(/* webpackChunkName: "sentry" */'@sentry/vue').then(({ setUser }) => {
  setUser({ id, email, username: (first_name + ' ' + last_name).trim() });
});

Expected Result

Sentry to initialize correctly

Actual Result

TypeError: init is not a function

This happened between 7.15 (last known working version) and 7.16

The @sentry/core dynamic import still seems to work, but the init one is specific to @sentry/vue and cannot be used with a dynamic import anymore

@Lms24
Copy link
Member

Lms24 commented Oct 25, 2022

Hi @Tofandel thanks for writing in!

I have a couple of questions to get to the bottom of this:

  • Which bundler are you using? (Webpack/Vite?)
  • Which Vue version are you using? (Vue2?)
  • It seems you're using the Vue SDK partially on the server (process.env). Would you mind sharing a little bit about your setup?

Looking at the 7.16.0 Changelog, I don't see anything at the top of my head that would mess with the Vue SDK's exports. The only Vue PR was #5983 which just changes something under the hood of our routing instrumentation. Just to confirm, are you using our Vue routing instrumentation?

I briefly tried reproducing this with Vite but your comment suggests you're using WebPack. Would you be able to provide a minimal repro app to debug this further?

@Tofandel
Copy link
Author

Tofandel commented Oct 25, 2022

I also had a look at the commit history and could not see what would cause this, I'll look if it's possible it's an updated deep dependency, but I can always reproduce by switching between 7.15 and 7.16

I'm using webpack and vue2, I'll look into adding a reproduction repo

@Tofandel
Copy link
Author

So I'm building a repro, but in the meantime, the issue is only with jest and is due to

jest.mock('@sentry/vue');

It seems this is what broke

@Tofandel
Copy link
Author

Tofandel commented Oct 25, 2022

I found the cause of the issue within jest and opened a PR there, it seems the build may be the culprit as it now provides the module with the [Symbol.toStringTag]: { value: 'Module' } which jest does not handle correctly

jestjs/jest#13513

If anybody is interested in the repro https://github.com/Tofandel/sentry-vue-bug

@Tofandel Tofandel changed the title Broken @sentry/vue dynamic imports Broken @sentry/vue jest mock Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants