安装nvm后,会出现很多编译错误



对于我正在处理的另一个项目,我安装了nvm for windows,在我的项目#1上,我没有任何tsconfig.json文件,只安装了tsc index.ts --sourceMap

作为一只小狗,我很开心,但自从安装了nvm(这建议我删除我以前安装的本地Node文件夹——我遵循了这个建议(。我收到了很多错误

controller/game.ts(165,45): error TS2339: Property 'find' does not exist on type 'Player[]'.
controller/http_server.ts(2,49): error TS2307: Cannot find module 'http'.
controller/http_server.ts(50,17): error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i @types/node`.
index.ts(7,12): error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i @types/node`.
index.ts(10,35): error TS2304: Cannot find name '__dirname'.

我的测试(mocha(导致了更多的错误

test/test.ts(10,1): error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.
test/test.ts(12,5): error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

这是我的包.json

{
"name": "myProj",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"engines": {
"node": "12.14"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"xml2js": "^0.4.23"
},
"devDependencies": {
"mocha": "^7.1.1"
}
}

我有点不愿意在这么痛苦的情况下定义tsconfig,但如果我必须这样做,我会

如错误所示,您必须为指定的包安装typescript编译器,如npm install--save dev@types/node等。

最新更新