sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

`@sentry/browser`'s `require` types are missing

Open davidmurdoch opened this issue 1 year ago • 0 comments

Is there an existing issue for this?

  • [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • [X] I have reviewed the documentation https://docs.sentry.io/
  • [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/browser

SDK Version

8.7.0

Framework Version

No response

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

Init a new node project (I used node 20 with yarn 1)

run:

yarn init -y

run:

yarn add [email protected] @sentry/[email protected]

create tsconfig.json:

{
    "compilerOptions": {
        "strict": true, // changes type warning to error
        "moduleResolution": "node16" // causes typescript to use `require` resolution instead of `import`
    }
}

create index.ts:

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

You'll find that the project can't compile because import * as Sentry from "@sentry/browser"; errors because Could not find a declaration file for module '@sentry/browser'.

This is because the package.json for '@sentry/browser' (the published version, not the version in this repo) has this exports section:


"exports": {
    "./package.json": "./package.json",
    ".": {
      "import": {
        "types": "./types/index.d.ts",
        "default": "./esm/index.js"
      },
      "require": {
        "types": "./build/npm.types/index.d.ts",
        "default": "./cjs/index.js"
      }
    }
  },
  

which specifies that require types live at ./build/npm.types/index.d.ts, but this file doesn't exist.

Maybe related, but the published package.json doesn't match what's in this repo at time of release. Yikes.

Expected Result

types should work

Actual Result

types don't work

davidmurdoch avatar May 30 '24 22:05 davidmurdoch