brendanashworth / generate-password

NodeJS library for generating cryptographically-secure passwords.
MIT License
354 stars 67 forks source link

Fix exports for ESM #83

Closed LukeNotable closed 1 year ago

LukeNotable commented 1 year ago

When trying to import generate-password from a TypeScript project built as ES Module (rather than CommonJS), it gives the error:

Could not find a declaration file for module 'generate-password'.

My temporary workaround has been to add this to tsconfig.json:

    "paths": {
      "generate-password": ["./node_modules/generate-password/src/generate.d.ts"]
    },

Basically, the types are not declared correctly for consumption by ESM. You can check this on Are the Types Wrong?, or using its CLI:

npx @arethetypeswrong/cli --pack .

This PR updates the exports field in package.json to something that passes the above check and works in my ESM project (as well as CJS projects).

ruimcf commented 1 year ago

👍

brendanashworth commented 1 year ago

Thanks for the contribution @LukeNotable , merged in https://github.com/brendanashworth/generate-password/commit/5068595ab3e7f3d85ec5b8f1f513cb30c0b1d296!

brendanashworth commented 1 year ago

and it's also published as 1.7.1