簡體   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