nuxt-community / sentry-module

Sentry module for Nuxt 2
https://sentry.nuxtjs.org
MIT License
500 stars 113 forks source link

Sentry: nuxtCtx.tryUse is not a function #557

Closed febriardis closed 1 year ago

febriardis commented 1 year ago

Version

@nuxtjs/sentry: 7.1.13 nuxt: nuxt bridge

when npm run dev i get error like this:

image

rchl commented 1 year ago

What does yarn why unctx or npm why unctx say?

febriardis commented 1 year ago

unctxis from sentry module. But now, i use sentry version 7.1.3, it's no such issue in my project

rchl commented 1 year ago

If you are not gonna answer my questions then I won't be able to help you. Using older version is not really a solution to the issue.

febriardis commented 1 year ago

@rchl this is bro image

rchl commented 1 year ago

This is with latest module version?

balesniy commented 1 year ago

I have same problem image

rchl commented 1 year ago

I would expect there to be an error if 0.0.3 version of unctx is used but this module only imports unctx from the root of the module so I would expect it to resolve to the one within the @nuxtjs/sentry package. Maybe Bridge changes something about where module's code is executed from... Any idea @danielroe ?

danielroe commented 1 year ago

No, Nuxt Bridge shouldn't change how the module code is executed or its dependencies are imported; jiti (used in pure Nuxt 2 as well) will be handling that, but it may well be an issue stemming from there (cc: @pi0).

I would recommend updating the critters module; the current version is much newer and depends on nuxt/kit v3.4.3.

rchl commented 1 year ago

Wouldn't upgrading to latest version of @nuxtjs/critters create additional type issues due to inclusion of @nuxt/schema? At least when running yarn tsc without skipLibCheck?

I've tried to reproduce it by installing @nuxtjs/critters@0.2.0 module and also by forcing unctx@0.0.3 to be hoisted but I couldn't reproduce.

Maybe the jiti dependency or some related one is outdated in your project and triggers some already fixed bug? You could run npm upgrade or yarn upgrade to update all dependencies including the implicit ones and see if that fixes it. Or alternatively delete the lock file and node_modules manually and re-install dependencies.

rchl commented 1 year ago

This issue coincidentally hit me now, when I've installed nuxt-timings in my project. And I now see why it's happening.

It's because the old version of unctx creates nuxt context first and then when the new version of unctx used by this project expects to find tryUse in the context, it can't find it.

By design unctx operates on global variable so having different versions of it in use at the same time causes issues.