对于另一个我正在从事的项目,我为Windows安装了nvm,在我的项目#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`.
这是我的package.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,但是如果需要的话-我会
答案 0 :(得分:1)
按照错误提示,您必须为该指定的软件包安装打字稿编译器,例如npm install --save-dev @ types / node等。