【发布时间】:2018-09-05 09:11:49
【问题描述】:
我正在测试 nest.js 框架,但我正在努力使用 VSCode 运行它,以便正确调试我的代码。这与此处Running nest.js from VS Code 描述的问题几乎相同。但是我确保我使用的是最新的软件包。我总是收到这个错误:
Error: Cannot find module 'cats/cats.module'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (c:\Users\user\Documents\random-api\dist\app.module.js:11:26)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
npm run start 完美运行,但我想用 VSCode IDE 调试应用程序。
我的 package.json 依赖项:
"dependencies": {
"@nestjs/common": "^4.6.6",
"@nestjs/core": "^4.6.6",
"@nestjs/microservices": "^4.6.6",
"@nestjs/testing": "^4.6.6",
"@nestjs/websockets": "^4.6.6",
"reflect-metadata": "^0.1.12",
"rxjs": "^5.5.7",
"typescript": "^2.7.2"
},
"devDependencies": {
"@types/express": "^4.11.1",
"@types/jest": "^22.2.2",
"@types/node": "^9.6.0",
"@types/supertest": "^2.0.4",
"jest": "^22.4.3",
"nodemon": "^1.17.2",
"prettier": "^1.11.1",
"supertest": "^3.0.0",
"ts-jest": "^22.4.2",
"ts-node": "^5.0.1",
"tsconfig-paths": "^3.1.3",
"tslint": "5.9.1",
"tslint-microsoft-contrib": "^5.0.3"
},
我的 vscode 的 launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}\\dist\\main.js",
"smartStep": true,
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
]
}
]
}
我尝试使用 typescript 文件作为路径的相同 launch.json,但抛出了相同的异常:
"program": "${workspaceFolder}\\src\\main.ts",
【问题讨论】:
-
所以我已经确保所有依赖项都在那里,确保你所有的 vs 代码插件都是更新的。有时一个有问题的插件会导致 vs 代码给出这样的错误,
-
Vscode 和所有插件都是最新的。
-
我认为它与“相对进口”有关。当我使用
import { PlayersModule } from './players/players.module';而不是import { PlayersModule } from 'players/players.module';它工作正常。 -
以下是对我有用的分步说明:Step by step instructions
标签: typescript