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

Fix missing 'exports.types' field of package.json #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dalboris
Copy link

@dalboris dalboris commented Dec 6, 2024

In a recent project set up with Vite+Typescript, I installed threejs-math (npm install threejs-math) and imported some types:

import { Vector2 } from "threejs-math";

But I got the following Typescript errors in my IDE (Sublime Text 4 with LSP-Typescript plugin):

There are types at `/home/boris/myproject/node_modules/threejs-math/types/index.d.ts`, but this result could not be resolved when respecting package.json "exports". The 'threejs-math' library may need to update its package.json or typings.

At first I thought it was probably a configuration problem of my project, my installation, or my IDE, but I couldn't fix it that way.

So following the suggestion of the error message, I looked online and found many projects having the same problem, which seems caused by the addition of new module resolution methods in recent versions of Typescript, see the following threads:

The solution seems indeed to add the following to threejs-math/package.json :

{
  "exports": {
    ".": {
      "types": "./types/index.d.ts"
    }
  }
}

I tested this change and indeed it makes the error message go away in my case, and all types are now properly imported in my project.

@dalboris
Copy link
Author

dalboris commented Dec 6, 2024

Also see the following page, checking whether there's indeed something to be changed in threejs-math package.json:

https://arethetypeswrong.github.io/?p=threejs-math

image

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

Successfully merging this pull request may close these issues.

1 participant