繁体   English   中英

错误:找不到模块“jsonwebtoken”或其对应的类型声明 NODE.JS 和 TYPESCRIPT

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

你好朋友你好朋友,我在导入 jsonwebtoken 时遇到问题,我已经安装了所有东西并且一切似乎都是正确的但我无法导入它,它给我的错误如下: TSError:⨯无法编译 TypeScript:src/routes/ auth.ts(5,17):错误 TS2307:找不到模块“jsonwebtoken”或其相应的类型声明。

这是代码,非常感谢你提前。

包Json:

{
"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"]

}

认证.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 :我已经尝试了一切,删除 node_modules 和 packageJson.lock 并再次运行 npm 安装命令没有结果

该项目已被码头化 docker -compose-yml

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

我通过删除这部分代码找到了解决方案: - /back/node_modules来自docker-compose.yml

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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