getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.77k stars 1.52k forks source link

ESM import issue for @clerk/clerk-sdk-node hoisted dependency #12122

Closed danilofuchs closed 1 month ago

danilofuchs commented 1 month ago

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

8.2.0

Framework Version

No response

Link to Sentry event

No response

SDK Setup

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

Sentry.init({
  dsn: "https://6bdb60d7e6f94dc291174f0839f8290c@o1428919.ingest.sentry.io/6779396",

  // Set tracesSampleRate to 1.0 to capture 100%
  // of transactions for performance monitoring.
  // We recommend adjusting this value in production
  tracesSampleRate: process.env.NODE_ENV === "prod" ? 0.2 : 1,
  profilesSampleRate: 1, // Relative to tracesSampleRate

  environment: process.env.NODE_ENV,
  enabled: process.env.NODE_ENV === "prod",
});

Steps to Reproduce

Install @clerk/clerk-sdk-node and import it before app.js

Run app with sentry: node --import instrumentation.js app.js

Expected Result

Should import @clerk/backend from node_modules/@clerk/backend (hoisted by NPM)

Actual Result

Is trying to import @clerk/backend from node_modules/@clerk/clerk-sdk-node/node_modules/@clerk/backend

> node --import ./build/instrumentation.js build/server.js

node:internal/process/esm_loader:34
      internalBinding('errors').triggerUncaughtException(
                                ^
[Error: ENOENT: no such file or directory, open '/home/danilo/salvy/salvy-api/node_modules/@clerk/clerk-sdk-node/dist/esm/@clerk/backend'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/home/danilofuchs/project/node_modules/@clerk/clerk-sdk-node/dist/esm/@clerk/backend'
}
AbhiPrasad commented 1 month ago

@danilofuchs thank you for writing in!

Could you share your package.json with us? To see what dependencies/dependency versions you are using?

timfish commented 1 month ago

This might be another occurrence of #12059

danilofuchs commented 1 month ago

package.json

"devDependencies": {
    "@redocly/cli": "^1.12.2",
    "@swc/cli": "^0.3.12",
    "@swc/core": "^1.5.5",
    "@testcontainers/postgresql": "^10.9.0",
    "@tsconfig/node20": "^20.1.4",
    "@types/bcrypt": "^5.0.2",
    "@types/chai": "^4.3.11",
    "@types/chai-as-promised": "^7.1.8",
    "@types/jsdom": "^21.1.6",
    "@types/jsonwebtoken": "^9.0.6",
    "@types/koa": "^2.15.0",
    "@types/koa__cors": "^5.0.0",
    "@types/koa__multer": "^2.0.7",
    "@types/koa__router": "^12.0.4",
    "@types/koa-bodyparser": "^4.3.12",
    "@types/lodash-es": "^4.17.12",
    "@types/node": "^20.12.11",
    "@types/pg": "^8.11.6",
    "@types/sinon": "^17.0.3",
    "@types/sinon-chai": "^3.2.12",
    "@types/ssh2-sftp-client": "^9.0.3",
    "@types/supertest": "^6.0.2",
    "@types/uuid": "^9.0.8",
    "@typescript-eslint/eslint-plugin": "^7.8.0",
    "@typescript-eslint/parser": "^7.8.0",
    "@vitest/coverage-v8": "^1.6.0",
    "@vitest/ui": "^1.2.2",
    "chai": "^4.4.1",
    "chai-as-promised": "^7.1.2",
    "dotenv": "^16.4.5",
    "eslint": "^8.57.0",
    "eslint-config-prettier": "^9.1.0",
    "eslint-plugin-no-only-tests": "^3.1.0",
    "eslint-plugin-path": "^1.3.0",
    "eslint-plugin-prettier": "^5.1.3",
    "eslint-plugin-tsdoc": "^0.2.17",
    "msw": "^2.3.0",
    "nodemon": "^3.1.0",
    "openapi3-ts": "^4.3.1",
    "prettier": "^3.2.5",
    "rimraf": "^5.0.7",
    "sinon": "^17.0.2",
    "sinon-chai": "^3.7.0",
    "supertest": "^7.0.0",
    "ts-node": "^10.9.2",
    "tsconfig-paths": "^4.2.0",
    "type-fest": "^4.18.2",
    "typescript": "^5.4.5",
    "unplugin-swc": "^1.4.5",
    "vitest": "^1.2.2"
  },
  "dependencies": {
    "@anatine/zod-openapi": "2.2.1",
    "@aws-crypto/client-node": "^4.0.0",
    "@aws-sdk/client-eventbridge": "^3.577.0",
    "@aws-sdk/client-s3": "^3.577.0",
    "@aws-sdk/client-sns": "^3.577.0",
    "@aws-sdk/client-textract": "^3.577.0",
    "@aws-sdk/s3-request-presigner": "^3.577.0",
    "@clerk/clerk-sdk-node": "^4.13.14",
    "@knocklabs/node": "^0.6.11",
    "@koa/multer": "^3.0.2",
    "@koa/router": "^12.0.1",
    "@prisma/client": "^5.14.0",
    "@salvyltd/americanet-sdk": "^6.0.1",
    "@salvyltd/kamino-sdk": "^4.0.1",
    "@salvyltd/salvy-logger": "^3.1.2",
    "@sentry/cli": "^2.31.2",
    "@sentry/node": "^8.2.1",
    "@sentry/profiling-node": "^8.2.1",
    "@slack/web-api": "^7.0.4",
    "amazon-textract-response-parser": "^0.4.0",
    "axios": "^1.6.8",
    "bcrypt": "^5.1.1",
    "cpf-cnpj-validator": "^1.0.3",
    "csv-parse": "^5.5.6",
    "csv-stringify": "^6.4.6",
    "customerio-node": "^4.1.1",
    "date-holidays": "^3.23.12",
    "dayjs": "^1.11.11",
    "eventemitter2": "^6.4.9",
    "exponential-backoff": "^3.1.1",
    "googleapis": "^134.0.0",
    "inversify": "^6.0.2",
    "jsdom": "^24.0.0",
    "jsonwebtoken": "^9.0.2",
    "koa": "^2.15.3",
    "koa-bodyparser": "^4.4.1",
    "lodash-es": "^4.17.21",
    "multer": "^1.4.5-lts.1",
    "node-cache": "^5.1.2",
    "openai": "^4.33.1",
    "pg": "^8.11.5",
    "pg-boss": "^9.0.0",
    "prisma": "^5.14.0",
    "redis": "^4.6.14",
    "reflect-metadata": "^0.2.2",
    "sqs-consumer": "^10.3.0",
    "ssh2-sftp-client": "^10.0.3",
    "stripe": "^15.5.0",
    "svix": "^1.21.0",
    "tiny-glob": "^0.2.9",
    "unleash-client": "^5.5.2",
    "uuid": "^9.0.1",
    "zod": "^3.22.4",
    "zod-validation-error": "^3.3.0"
  }
timfish commented 1 month ago

@danilofuchs if you are able, could you try the patch mentioned here.

There are PRs awaiting merging in upstream libraries but this would help confirm if it's a duplicate issue.

AbhiPrasad commented 1 month ago

We released https://github.com/getsentry/sentry-javascript/releases/tag/8.8.0 which should fix this issue. Please give it a try!