Skip to content

TypeScript source files in "types" exports can cause compilation errors (npm) #446

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

Closed
frangio opened this issue Apr 25, 2024 · 9 comments
Closed
Assignees

Comments

@frangio
Copy link

frangio commented Apr 25, 2024

In #377 the package.json files for npm where changed so that the source .ts files are used for "types" exports instead of .d.ts files as was done previously. This is not right, because when such a package is installed and imported in a TypeScript file, TypeScript will try to compile the dependency source file with the project's compilation settings, which may be different and cause compilation errors, for example, due to different settings for noUncheckedIndexedAccess.

The original issue #313 that was marked as fixed proposed adding declaration maps and source files in addition to the compiled .d.ts files that go in "types" exports. This allows "go to definition" to work as expected, and does not cause the compilation errors that the current approach causes.

@github-project-automation github-project-automation bot moved this to Needs Triage in JSR Apr 25, 2024
@lucacasonato
Copy link
Member

Oh this is not intentional - do you have an example where this is happening? It should not point to .ts files ever 😓

@lucacasonato lucacasonato moved this from Needs Triage to Needs Plan in JSR Apr 26, 2024
@frangio
Copy link
Author

frangio commented Apr 26, 2024

I noticed it when installing the package @noble/secp256k1.

The contents of https://npm.jsr.io/~/8/@jsr/noble__secp256k1/2.1.0.tgz are:

package/LICENSE
package/README.md
package/index.js
package/index.ts
package/jsr.json
package/package.json

and package.json looks like this:

{
  "name": "@jsr/noble__secp256k1",
  "version": "2.1.0",
  "homepage": "https://jsr.io/@noble/secp256k1",
  "type": "module",
  "dependencies": {},
  "exports": {
    ".": {
      "types": "./index.ts",
      "default": "./index.js"
    }
  },
  "_jsr_revision": 8
}

@alexgleason
Copy link

Wow, this explains a lot! I have been fighting with this issue for several days. Source files of JSR packages are getting type-checked.

image

AbortSignal.any is not available in vanilla TypeScript (even though browsers support it). And my client code in Node is getting type errors from the package implementation instead of just caring about the signatures.

@lucacasonato
Copy link
Member

Great - thanks. I'll get this fixed today

@lucacasonato lucacasonato moved this from Needs Plan to Ready in JSR Apr 29, 2024
@lucacasonato lucacasonato self-assigned this Apr 29, 2024
@lucacasonato
Copy link
Member

I can reproduce - this happens for packages that are using slow types, so where no d.ts file is emitted.

github-merge-queue bot pushed a commit that referenced this issue Apr 29, 2024
This was happening for packages that had slow types.

Fixes #446
@github-project-automation github-project-automation bot moved this from Ready to Done in JSR Apr 29, 2024
@alexgleason
Copy link

I'm still struggling with it. Not sure if it's my fault. The package does not have slow types.

In node_modules/@nostrify/nostrify I have NPool.ts, NPool.js, and NPool.d.ts.

If I delete NPool.ts manually then it works fine.

My bundler (Vite) is trying to load the .ts source file for some reason.

@lucacasonato
Copy link
Member

It will be working tomorrow - there is one more PR that needs to land (#463), and then all the tarballs will be regenerated in the background over the course of tomomrrow - I'll let you know once it's actually fixed in prod :)

@lucacasonato lucacasonato reopened this Apr 29, 2024
@lucacasonato lucacasonato moved this from Done to In Progress in JSR Apr 29, 2024
@lucacasonato
Copy link
Member

@alexgleason This is now fixed. Remove your lockfile and re-run npm i to get an updated node_modules/ folder.

@github-project-automation github-project-automation bot moved this from In Progress to Done in JSR Apr 30, 2024
@alexgleason
Copy link

It works now. Thank you @lucacasonato !! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

3 participants