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

eslint(import/namespace): error 'BrowserTracing' not found in imported namespace 'Sentry' #9728

Closed
3 tasks done
brettdh opened this issue Dec 4, 2023 · 25 comments
Closed
3 tasks done
Labels
Package: remix Issues related to the Sentry Remix SDK Type: Bug

Comments

@brettdh
Copy link

brettdh commented Dec 4, 2023

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/remix

SDK Version

7.84.0

Framework Version

Remix 2.1.0

Link to Sentry event

n/a

SDK Setup

  Sentry.init({
    dsn: window.SENTRY_DSN,
    environment: window.SENTRY_ENVIRONMENT,
    tunnel: "/api/internal/sentry_proxy",
    tracesSampleRate: 1,
    replaysSessionSampleRate: 0.1,
    replaysOnErrorSampleRate: 1,

    beforeSend(event) {
      if (event.exception) {
        errorHook(event)
      }
      return event
    },

    integrations: [
      new Sentry.BrowserTracing({
        routingInstrumentation: Sentry.remixRouterInstrumentation(
          useEffect,
          useLocation,
          useMatches,
        ),
      }),
      new Sentry.Replay({
        maskAllText: false,
        maskAllInputs: false,
        blockAllMedia: false,
      }),
    ],
  })

Steps to Reproduce

  1. Configure Remix SDK as described in the setup guide (mine above has some small additions)
  2. Run eslint with recommended config

Expected Result

No eslint error

Actual Result

Some variation of #4569 and #6705:

  32:18  error  'BrowserTracing' not found in imported namespace 'Sentry'  import/namespace
  39:18  error  'Replay' not found in imported namespace 'Sentry'          import/namespace
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Dec 4, 2023
@github-actions github-actions bot added the Package: remix Issues related to the Sentry Remix SDK label Dec 4, 2023
@lforst
Copy link
Member

lforst commented Dec 4, 2023

Hi, how did you import Sentry?

@brettdh
Copy link
Author

brettdh commented Dec 4, 2023

As directed in the setup guide:

import * as Sentry from "@sentry/remix";

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Dec 4, 2023
@lforst
Copy link
Member

lforst commented Dec 4, 2023

Would you mind sharing a small reproduction repo where we can generate this bug? Thanks!

Our generated types look fine so I am surprised you're running into this.

@brettdh
Copy link
Author

brettdh commented Dec 6, 2023

Here you go: https://github.com/brettdh/sentry-remix-eslint-repro

Steps I took:

  1. Run npx create-remix@latest --template remix-run/grunge-stack . (brettdh/sentry-remix-eslint-repro@50a7dbb)
  2. Tidy up a couple things and commit the results of the remix.init script (brettdh/sentry-remix-eslint-repro@dfacdee)
  3. Run npx @sentry/wizard@latest -i remix and fix unrelated import/order errors (brettdh/sentry-remix-eslint-repro@9635d84)

TIL that Github Actions has inline code annotations for checks like eslint 😮 as the errors I mentioned in the initial post also appear in that last commit I linked.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Dec 6, 2023
@Lms24
Copy link
Member

Lms24 commented Dec 7, 2023

My suspicion is that eslint is trying to resolve the Sentry import and picking the wrong entry point of the @sentry/remix package. Namely, the server entry point instead of the client one:

"main": "build/cjs/index.server.js",
"module": "build/esm/index.server.js",
"browser": "build/esm/index.client.js",
"types": "build/types/index.types.d.ts",

We rely on these entry points so that the bundler picks up the correct client or server SDK.

Not sure how to solve this though other than ignoring the rule for the Sentry import (which I totally get is not ideal). We briefly talked about shimming server and client-only exports in the respective opposite bundles (#9594) but it'd come with a cost possible bundle size increases and having to maintain these shims.

@mmospanenko
Copy link

mmospanenko commented Feb 21, 2024

Got the same issue with replayIntegration using pnpm, "@sentry/react": "^7.102.0"
image

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

lforst commented Feb 21, 2024

@mmospanenko can you try deleting your node modules, cleaning your pnpm chache, and reinstalling everything? Thanks.

@mmospanenko
Copy link

yes, I was playing with it, but let me do it again. I use pnpm monorepo and Sentry only in one package (It could this behavior... maybe we should install all deps explicitly, etc)

  1. rm -rf node_modules packages/*/node_modules
  2. rm -rf $(pnpm store path)
  3. pnpm i from root

the same:
image

I import it as import * as Sentry from '@sentry/react';

and have only Sentry (other ton of packages ok) errors in ESLint after migration from Yarn to pnpm:

 24:10  error  'captureException' not found in imported namespace 'Sentry'  import/namespace
 20:12  error  'replayIntegration' not found in imported namespace 'Sentry'  import/namespace

ESLint rules are 'recommended' default mostly, import/namespace as is

@binajmen
Copy link

@lforst I'm facing the same issue. I don't mind give you access to my private repo if that is okay for you?

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

lforst commented Feb 23, 2024

@binajmen For sure, although a minimal reproduction would be more ideal, just to isolate the actual issue.

@binajmen
Copy link

@lforst I've just added you to the project. Unfortunately, I won't be able to create a reproducible example until next week. In the meantime, feel free to clone the repository if you have some time to spare. Currently, the project is not too extensive, so you shouldn't encounter much interference. :)

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

lforst commented Feb 23, 2024

@binajmen Thank you! A public reproduction would be awesome so that other people can pick this up too! I will try to take a look.

@lforst
Copy link
Member

lforst commented Feb 23, 2024

I think this is a bug in eslint-plugin-import that our SDK just happens to run into. Would you mind raising an issue there?

I don't feel the need to fix this in the SDK because Typescript itself and other eslint plugins are able to resolve the exports just fine 🤔

@binajmen
Copy link

I have opened an issue on the eslint-plugin-import repository. Please feel free to add to it, as I was unable to provide detailed information.

Would the best workaround be to temporarily ignore these ESLint errors?

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

lforst commented Feb 27, 2024

@binajmen thank you! A maintainer has answered there and clarified. With that information, I can say that we simply have an incompatibility with eslint-plugin-import that we will not fix (at least in the near future).

The SDK has different exports depending on which context it is run (server or client) and we currently do not have plans to align them. The TS type definitions are isomorphic and complete and our source of truth. If you want you can rely on those.

Closing as wont-fix (for now).

@lforst lforst closed this as not planned Won't fix, can't repro, duplicate, stale Feb 27, 2024
@binajmen
Copy link

@lforst thank you, not sure how I'll fix the lint issue but at least we know ;)

@ljharb
Copy link

ljharb commented Feb 27, 2024

fwiw, that's a very confusing API, and strongly suggests it should be split into two packages if it's not going to be aligned.

@GOWxx
Copy link

GOWxx commented May 12, 2024

Got the same issue with replayIntegration using pnpm, "@sentry/react": "^7.102.0"

same error.

@lforst
I created a repository, hoping this can help you. Thank you for your hard work and dedication!

Minimum Reproducible Repository:

https://github.com/GOWxx/remix-pnpm-sentry-eslint-namespace-error-repo

remix-vite-sentry-namespace-error

@lforst
Copy link
Member

lforst commented May 14, 2024

@GOWxx we will not fix this. Please see import-js/eslint-plugin-import#2969 (comment)

@GOWxx
Copy link

GOWxx commented May 16, 2024

@GOWxx we will not fix this. Please see import-js/eslint-plugin-import#2969 (comment)

Thank you for your reply. I will look for information related to TS import resolver to try and solve the issue. Thank you!

guesung added a commit to guesung/Web-Memo that referenced this issue Sep 13, 2024
* feat: @sentry/react를 설치한다

* feat: sentry sourcemap을 추가한다

* feat: ErrorBoundary에 sentry 에러 추적을 추가한다

* feat: initSentry와 testSentry를 모듈화한다

* feat: NewTab, Options, SidePanel에서 Sentry를 설정한다

* feat: release에 현재 package.json기준 버전을 추가한다

* feat: @sentry/vite-plugin를 전역에 설치한다

* fix: 브라우저에서는 fs모듈을 사용하지 못하기에 제거한다

* fix: release값을 string으로 정의한다

* feat: eslint-plugin-import와 Sentry의 호환 이슈로, ESlint 무효화 주석을 추가한다

ref : getsentry/sentry-javascript#9728

* feat: options와 new-tab에도 vite config에 sentry설정을 추가한다

* feat: build CI 과정에서 .env에 vite auth token을 삽입한다

* feat: eslint-plugin-import와 Sentry의 호환 이슈로, ESlint 무효화 주석을 추가한다

ref : getsentry/sentry-javascript#9728

* feat: dsn값을 환경변수로 주입한다

* refactor: tsconfig.json의 module을 base.json에서 일괄 관리한다

* feat: build과정에서 환경변수를 주입한다

* feat: sentry 테스트 코드를 제거한다

* fix: options의 type:module을 제거한다

* feat: sentry 관련 환경 변수를 vite-env.d.ts와 turbo.json에 추가한다

* feat: 배포된 환경인지 체크하는 isProduciton 유틸함수를 구현한다

ref : https://developer.chrome.com/docs/extensions/reference/api/management#type-ExtensionInstallType

* refactor: 함수이기에 `getIsProduction`으로 네이밍을 수정한다

* feat: 환경에 따라 tracesSampleRate값을 다르게 설정한다

ref : https://docs.sentry.io/platforms/javascript/tracing/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: remix Issues related to the Sentry Remix SDK Type: Bug
Projects
Archived in project
Archived in project
Development

No branches or pull requests

8 participants