ค้นหาเว็บไซต์

การติดตั้ง - ข้อผิดพลาดในการติดตั้ง/เวอร์ชัน TypeScript: ไม่รู้จักคำว่า 'tsc'


การตั้งค่าโปรเจกต์บนคอมพิวเตอร์เครื่องใหม่และพบปัญหาเกี่ยวกับเวอร์ชันของ TypeScript ฉันได้ลอง:

npm install -g typescript
npm install typescript
npm install -g [email 
npm install -g [email 

แต่ทุกครั้งที่ฉันพยายามตรวจสอบเวอร์ชันโดยใช้:

tsc -v

ฉันได้รับข้อผิดพลาดดังต่อไปนี้:

The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path wa
s included, verify that the path is correct and try again.
At line:1 char:4
+ tsc <<<<  -v
    + CategoryInfo          : ObjectNotFound: (tsc:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException 

สำหรับการอ้างอิง ไฟล์ package.json ประกอบด้วย:

"scripts": {
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings",
    "gulp": "gulp",
    "build-dev": "gulp",
  },
"devDependencies": {
    "gulp": "^3.9.1",
    "gulp-concat": "^2.6.0",
    "gulp-inline-ng2-template": "^4.0.0",
    "gulp-typescript": "^3.0.2",
    "path": "^0.12.7",
    "systemjs-builder": "^0.15.26",
    "typescript": "^2.1.6",
    "typings": "^2.0.0"
  }

เมื่อฉันรัน tsc -v บนเครื่องของฉัน (ซึ่งใช้งานได้) ฉันได้รับ

Version 2.0.10

ติดอยู่กับสิ่งที่ฉันต้องทำเพื่อให้ติดตั้ง TypeScript แล้วคำสั่ง tsc ถูกจดจำ?

คำตอบ #1

ถ้าปัญหานี้มาจากเชลล์คำสั่งของคุณ ให้ติดตั้ง npm เวอร์ชันล่าสุดก่อน จากนั้นลองติดตั้ง TypeScript อีกครั้ง

ถ้าคุณกำลังใช้ VS CODE สำหรับการพัฒนาและเจอปัญหาในเทอร์มินัลของ VS Code เมื่อคุณรันงาน tsc build: ถ้าคุณติดตั้ง TypeScript จาก Visual Studio 2015/2017 และเส้นทางอยู่ในตัวแปรสภาพแวดล้อม ให้ลบมันออกก่อน แล้วทำการรีสตาร์ทและลองอีกครั้ง

ฉันมีปัญหาเดียวกับที่คุณมี และฉันแก้มันได้ผ่านขั้นตอนข้างต้น

บทความที่เกี่ยวข้อง