[英]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.你好朋友你好朋友,我在导入 jsonwebtoken 时遇到问题,我已经安装了所有东西并且一切似乎都是正确的但我无法导入它,它给我的错误如下: TSError:⨯无法编译 TypeScript:src/routes/ auth.ts(5,17):错误 TS2307:找不到模块“jsonwebtoken”或其相应的类型声明。
Here is the code, thank you very much in advance.这是代码,非常感谢你提前。
packageJson:包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: tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"moduleResolution": "node",
"experimentalDecorators": true,
"sourceMap": true,
"outDir": "dist/src"
},
"lib": ["es2015"]
} }
Auth.ts认证.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 PD :我已经尝试了一切,删除 node_modules 和 packageJson.lock 并再次运行 npm 安装命令没有结果
THE PROJECT IS DOCKERIZED docker-compose-yml该项目已被码头化 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我通过删除这部分代码找到了解决方案: - /back/node_modules来自docker-compose.yml
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.