js-three icon indicating copy to clipboard operation
js-three copied to clipboard

Export types in package.json

Open Krassnig opened this issue 2 years ago • 3 comments


Is your feature request related to a problem? Please describe.

When installing @googlemaps/three and importing with typescript via import { ThreeJSOverlayView } from '@googlemaps/three'; I get an error Could not find a declaration file for module '@googlemaps/three'. '.../google-maps-webgl/node_modules/@googlemaps/three/dist/index.esm.js' implicitly has an 'any' type. There are types at '.../google-maps-webgl/node_modules/@googlemaps/three/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@googlemaps/three' library may need to update its package.json or typings.

Describe the solution you'd like Export the dist/index.d.ts as well.

package.json before:

  "main": "dist/index.umd.js",
  "exports": {
    ".": {
      "import": "./dist/index.esm.js",
      "require": "./dist/index.umd.js",
      "umd": "./dist/index.umd.js",
      "browser": "./dist/index.esm.js",
    }
  },
  "unpkg": "dist/index.min.js",

package.json after:

  "main": "dist/index.umd.js",
  "exports": {
    ".": {
      "import": "./dist/index.esm.js",
      "require": "./dist/index.umd.js",
      "umd": "./dist/index.umd.js",
      "browser": "./dist/index.esm.js",
      "types": "./dist/index.d.ts"
    }
  },
  "unpkg": "dist/index.min.js",

Describe alternatives you've considered Making that change manually by editing the dependency inside my node_modules folder.

Krassnig avatar Sep 11 '23 07:09 Krassnig

If you would like to upvote the priority of this issue, please comment below or react on the original post above with :+1: so we can see what is popular when we triage.

@Krassnig Thank you for opening this issue. 🙏 Please check out these other resources that might help you get to a resolution in the meantime:

This is an automated message, feel free to ignore.

wangela avatar Sep 11 '23 07:09 wangela

Hi @Krassnig! Do you have an example-repo where this can be reproduced?
I think I saw that error before and it had something to do with the new moduleResolution: 'bundler' setting in the tsconfig, is that what you are using?

I think a problem with the proposed solution is that it's not clear which version of the package (umd or esm) the typings are for, but I will have a look into this.

usefulthink avatar Sep 11 '23 07:09 usefulthink

Yes, I have set "moduleResolution": "bundler" Here is a minimal reproduction of how I got the error: google-maps-imports.zip Basically I just did a npm create vite and chose typescript. Then installed @googlemaps/three and tried to import import { ThreeJSOverlayView } from '@googlemaps/three'; in src/main.ts

Krassnig avatar Sep 11 '23 08:09 Krassnig