简体   繁体   中英

ERROR: Cannot find module 'jsonwebtoken' or its corresponding type declarations with NODE.JS and TYPESCRIPT

Hello friends Hello friends, I have a problem when importing jsonwebtoken, I have everything installed and everything seems to be correct but I cannot import it, the error it gives me is the following: TSError: ⨯ Unable to compile TypeScript: src/routes/auth.ts(5,17): error TS2307: Cannot find module 'jsonwebtoken' or its corresponding type declarations.

Here is the code, thank you very much in advance.

packageJson:

{
"name": "back",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
    "start": "tsc && node dist/app.js",
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "nodemon --legacy-watch"
},
"author": "",
"license": "ISC",
"devDependencies": {
    "@types/express": "^4.17.13",
    "@types/node": "^17.0.24",
    "nodemon": "^2.0.15",
    "ts-node": "^10.7.0",
    "tslint": "^5.20.1",
    "typescript": "^4.6.3"
},
"dependencies": {
    "@types/jsonwebtoken": "^8.5.8",
    "body-parser": "^1.20.0",
    "cors": "^2.8.5",
    "crypto": "^1.0.1",
    "express": "^4.17.3",
    "jsonwebtoken": "^8.5.1",
    "pg": "^8.7.3"
}

}

tsconfig.json:

{
"compilerOptions": {
  "module": "commonjs",
  "esModuleInterop": true,
  "target": "es6",
  "moduleResolution": "node",
  "experimentalDecorators": true,
  "sourceMap": true,
  "outDir": "dist/src"
},
"lib": ["es2015"]

}

Auth.ts

import {Router} from 'express'
import  {Request, Response} from 'express'
import UserActions from '../actions/users';
import { UserType } from '../types/user';
import jwt from 'jsonwebtoken'; //ERROR IMPORT:TSError: ⨯ Unable to compile TypeScript: src/routes/auth.ts(5,17): error TS2307: Cannot find module 'jsonwebtoken' or its corresponding type declarations.

router.get('/', (req, res) => {
    res.send('PÁGINA INDEX auths!');
});

PD : I have tried everything, remove node_modules and packageJson.lock and run the npm install command again with no result

THE PROJECT IS DOCKERIZED docker-compose-yml

  back:
    build: ./back
    ports:
      - 3000:3000
    volumes:
      - ./back:/back
      - /back/node_modules
    container_name: Alda_Back

I found the solution by deleting this section of code: - /back/node_modules from the docker-compose.yml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM