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

问题描述 投票:0回答:1

对于我正在处理的另一个项目,我在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-但如果我必须这样做,我会

typescript mocha package.json tsc
1个回答
0
投票

按照错误提示,您必须为该指定的软件包安装打字稿编译器,例如npm install --save-dev @ types / node等。

© www.soinside.com 2019 - 2024. All rights reserved.