jose: Module not found: Can't resolve 'jose/jwt/sign'
Describe the bug
To Reproduce
- npm install jose
- Try to import like so: import { SignJWT } from “jose/jwt/sign”;
- Typescript compiler errors: Module not found: Can’t resolve ‘jose/jwt/sign’
Code to reproduce the behaviour: https://stackblitz.com/edit/react-ts-kkyw3y
Expected behaviour Should import correctly with no errors
Environment:
joseversion: v3.11.6- affected runtime is: Node.js 14.15.0
- other relevant library versions: typescript@4.2.4
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 24 (11 by maintainers)
I have this error in a standard create-react-app typescript setup. I think this should be re-opened and investigated. if we need to take care of something maybe the fix is just adding some guidance on the read.me file.
@dalegacusan you’re barking up the wrong tree - this is to be solved in your tooling, not here.
Same issue here when using the package with a vue-cli setup:
Using node v14.17.0
There’s no “main” entry because there’s no “main” package or export. It’s just submodules, using a node loader feature present in the supported runtimes. Tooling is slowly catching up, but is just not quite there yet.
Well, clearly they do - there are plenty of consumers of this package major already. Plus, see the proof of working code i’ve posted above.
https://nodejs.org/api/packages.html#packages_subpath_exports https://nodejs.org/api/packages.html#packages_conditional_exports
I’m solving this problem by importing the relevant files directly. I put this into an intermediate file
jose.tsand can then import like I expect to from that. Eg. like this:And then I can use it like this:
Yes I know I’m relying on internals here, but if it breaks, I can quickly fix it by editing one file on my end.