Skip to content

Commit

Permalink
fix: add types to exports map
Browse files Browse the repository at this point in the history
When TypeScript uses a `moduleResolution` of `Node16` or `NodeNext` and
an `exports` map is encountered, `main`, `types` and `typings` entries
declared on the `package.json` root are ignored so `types` needs to
be present in the exports map.

Fixes this sort of error:

```
src/index.ts:19:23 - error TS7016: Could not find a declaration file for module 'private-ip'. '/Users/alex/Documents/Workspaces/ipfs/helia-http-gateway/node_modules/private-ip/index.js' implicitly has an 'any' type.
  There are types at '/path/to/node_modules/private-ip/lib/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'private-ip' library may need to update its package.json or typings.

19 import isPrivate from 'private-ip'
```
  • Loading branch information
achingbrain committed Jan 2, 2024
1 parent 009c686 commit 346867a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"name": "private-ip",
"version": "3.0.1",
"description": "Check if IP address is private.",
"exports": "./index.js",
"exports": {
".": {
"types": "./lib/index.d.ts",
"import": "./index.js"
}
},
"type": "module",
"types": "lib/index.d.ts",
"repository": {
Expand Down

0 comments on commit 346867a

Please sign in to comment.