4

I installed the module. Only this module is not working other modules are working fine. When I trying to run it it's throwing following error

Error: Cannot find module 'jose'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (<my_folder>\test.js:1:100)     
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)   
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)

What I tried:

Almost everything from this stackoverflow question

  1. Removed node modules folder and installed again

  2. Cleared cache and installed again

  3. Installed npm install @types/node --save-dev

my package.json

{
  "name": "test-api",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "start": "func start",
    "test": "echo \"No tests yet...\""
  },
  "dependencies": {
    "axios": "^0.21.0",
    "axios-retry": "^3.1.9",
    "fs-extra": "^9.0.1",
    "qs": "^6.9.4"
  },
  "devDependencies": {
    "@types/node": "^14.14.10",
    "jose": "^3.1.3"
  }
}
2
  • 1
    How do you require your jose modules? Commented Nov 28, 2020 at 6:27
  • If everything is done correctly but still getting error --make sure you've node.js version > 12.x Commented Feb 17, 2021 at 19:05

5 Answers 5

4

The jose package exports individual ESM modules, as in, there's no root jose module in version 3.x that you're installing. You can read how to require/import each individual module in the project's documentation

Sign up to request clarification or add additional context in comments.

Comments

1

Update your NodeJS runtime. Fixed the issue for me.

Comments

1

I solved this problem on react as follows

import { jwtVerify } from 'jose/dist/browser/jwt/verify'

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
1

If you are using Nuxt you can resolve this error by adding the types into the build transpile option in nuxt.config.js like so:

 build: {
        transpile: ['@jose/dist/types']
    },

After this I am able to import everything from Jose like so:

import {jwtVerify, importSPKI} from "jose";

Doing it like this gives you full type descriptions and everything!

1 Comment

Was able to fix the error with Nuxt 3 in the bun runtime by setting transpile: ['jose'] (without the @). Thank you. For the node runtime I did not need to set anything...
-1

Maybe you should use npm install --save-dev jose to install jose :D

4 Comments

that's the first thing I done. thanks for the info :D
Not sure to understand... Is the Installed npm install @types/node --save-dev just a typo by copy/paste and you are ironic? Or did you did this mistake and you're are happy to realize it? I'm confuse. And the second case, give a link to the github to see package.json and so...
I updated my package.json file please check.thanks
Ok not helping, if you have a github with the project, maybe it can be fixed quickly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.