首页 > 解决方案 > 程序“tsc”未能运行:没有应用程序与此操作的指定文件关联

问题描述

下面是我在 package.json 中的 devDependencies

"@types/jasmine": "^3.6.2",
"@types/node": "^14.14.19",
"jasmine": "^3.6.3",
"protractor": "^7.0.0",
"typescript": "^4.1.3"

尝试运行时node_modules/typescript/bin/tsc Sample.ts出现以下错误:

Program 'tsc' failed to run: No application is associated with the specified file for this operation line:1 char:1
+ node_modules/typescript/bin/tsc Sample.ts

我的系统路径变量

C:\Users\chinm\AppData\Roaming\npm 
C:\Users\chinm\AppData\Local\Microsoft\TypeScript\4.0

标签: node.jsangulartypescript

解决方案


通常在文件顶部有一个 shebang 行

#!/usr/bin/env node

这指定了哪个程序应该运行脚本,但 Windows 操作系统不支持 shebang。因此,理想情况下,您不应使用此完整路径来运行tsc. 让包管理器处理这个问题。

如果您使用 npm 安装了 tsc,请使用:

npx tsc Sample.ts

纱线用途:

yarn tsc Sample.ts

推荐阅读