typescript 编译打字稿时找不到“tsc 命令”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39404922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'tsc command not found' in compiling typescript
提问by Aung Thet
I want to install typescript, so I used the following command:
我想安装打字稿,所以我使用了以下命令:
npm install -g typescript
and test tsc --version
, but it just show 'tsc command not found'. I have tried many ways as suggested in stackoverflow, github and other sites. but it doesn't work. How could I know typescript is installed and where it is.
和 test tsc --version
,但它只显示'tsc command not found'。我已经按照 stackoverflow、github 和其他站点中的建议尝试了很多方法。但它不起作用。我怎么知道打字稿已安装以及它在哪里。
my OS is Unix, OS X El Capitan 10.11.6, node version is 4.4.3, npm version is 3.10.5
我的操作系统是 Unix,OS X El Capitan 10.11.6,节点版本是 4.4.3,npm 版本是 3.10.5
回答by basarat
A few tips in order
按顺序的一些提示
- restart the terminal
- restart the machine
- reinstall nodejs + then run
npm install typescript -g
- 重启终端
- 重启机器
- 重新安装 nodejs + 然后运行
npm install typescript -g
If it still doesn't work run npm config get prefix
to see where npm install -g is putting files (append bin
to the output) and make sure that they are in the path (the node js setup does this. Maybe you forgot to tick that option).
如果它仍然不起作用npm config get prefix
,请运行以查看 npm install -g 放置文件的位置(附加bin
到输出)并确保它们在路径中(节点 js 设置执行此操作。也许您忘记勾选该选项)。
回答by Oscar Jovanny
I had to do this:
我不得不这样做:
npx tsc app.ts
回答by Pandi
If your TSC command is not found in MacOS after proper installation of TypeScript (using the following command: $ sudo npm install -g typescript
, then ensure Node /bin
path is added to the PATH
variable in .bash_profile
.
如果打字稿的正确安装(使用下面的命令后的MacOS没有找到您的TSC命令:$ sudo npm install -g typescript
,然后确保节点/bin
路径添加到PATH
变量.bash_profile
。
Open .bash_profile
using terminal: $ open ~/.bash_profile;
.bash_profile
使用终端打开: $ open ~/.bash_profile;
Edit/Verify bash profile to include the following line (using your favorite text editor):
编辑/验证 bash 配置文件以包含以下行(使用您喜欢的文本编辑器):
export PATH="$PATH:"/usr/local/lib/node_modules/node/bin"";
Load the latest bash profile using terminal: source ~/.bash_profile
;
使用终端加载最新的bash配置文件:source ~/.bash_profile
;
Lastly, try the command: $ tsc --version
.
最后,尝试命令:$ tsc --version
.
回答by Teja
Easy fix for Mac I found. Just run these commands:
我发现 Mac 的简单修复。只需运行这些命令:
sudo npm install -g concurrently
sudo npm install -g lite-server
sudo npm install -g typescript
Nothing worked except this for me.
除了这个对我来说没有任何效果。
回答by Per H?yer
you are all messing with the global installations and -path files. Just a little error might damage every project you have ever written, and you will spend the rest of the nite trying to get a console.log('hi') to work again:-=.
你们都在搞乱全局安装和 -path 文件。一个小错误可能会损坏您曾经编写的每个项目,并且您将花费整晚的时间来尝试让 console.log('hi') 再次工作:-=。
If you have run npm i typescript --save-dev in your project - just try to run:
如果您在项目中运行了 npm i typescript --save-dev - 只需尝试运行:
npx tsc
npx tsc
and see if it works before messing with global stuff (unless ofc you really know what you are doing)
并在弄乱全局内容之前查看它是否有效(除非您真的知道自己在做什么)
cheers
干杯
回答by sjs
This answer is specific for iTermV2 on MAC
此答案特定于 MAC 上的 iTermV2
First of all, I needed to instal as
sudo
(admin) during NPM installsudo npm install -g typescript
NPM installs the libraries under
/usr/local/Cellar/node/<your latest version>/lib/node_modules/typescript
folder and symlinks at/usr/local/Cellar/node/<your latest version>/bin/tsc
首先,我需要
sudo
在 NPM 安装期间以(管理员)身份安装须藤 npm install -g 打字稿
NPM 在
/usr/local/Cellar/node/<your latest version>/lib/node_modules/typescript
文件夹和符号链接下安装库/usr/local/Cellar/node/<your latest version>/bin/tsc
hence I went ~/.zshrc ( .bashrc, if you use bash)and added /usr/local/Cellar/node/<your latest version>/bin
to the $PATH.
因此我去了~/.zshrc(.bashrc,如果你使用bash)并添加/usr/local/Cellar/node/<your latest version>/bin
到$PATH。
- reload the shell profile via
source ~/.zshrc
(.bashrc in your case)
- 通过
source ~/.zshrc
(在您的情况下为 .bashrc )重新加载 shell 配置文件
回答by juan.pedro.v
The only solution that work for me was put npx tsc -v or for the compiling npx tsc salida.ts
对我有用的唯一解决方案是放置 npx tsc -v 或用于编译 npx tsc salida.ts
"salida.ts" is the name of the file
“salida.ts”是文件名
回答by Rodrigo Marques
I know this is an old question, but I had this same problem on Ubuntu 19.10 LTS.
我知道这是一个老问题,但我在 Ubuntu 19.10 LTS 上遇到了同样的问题。
To solve this I ran the following command:
为了解决这个问题,我运行了以下命令:
$ sudo apt install node-typescript
After that, I was able to use tsc
.
在那之后,我能够使用tsc
.
I hope it helps :)
我希望它有帮助:)
回答by Marjun
After finding all solutions for this small issue for macOS only.
Finally, I got my TSC works on my MacBook pro.
在为仅适用于 macOS 的这个小问题找到所有解决方案之后。
最后,我在我的 MacBook pro 上得到了我的 TSC 作品。
This might be the best solution I found out.
这可能是我发现的最佳解决方案。
For all macOS users, instead of installing typescript using npm, you can install typescript using homebrew.
对于所有 macOS 用户,您可以使用 homebrew 安装 typescript,而不是使用 npm 安装 typescript。
--> brew install typescript
--> brew install typescript
Please see attached screencap for reference.
请参阅随附的屏幕截图以供参考。
Thank you.
谢谢你。
回答by codeherk
Non-admin solution
非管理员解决方案
I do not have admin privileges since this machine was issued by my job.
我没有管理员权限,因为这台机器是我的工作发布的。
- get path of where node modules are being installed andcopy to clipboard
npm config get prefix | clip
- don't have clip? just copy output from
npm config get prefix
- add copied path to environment variables
- my preferred method (Windows)
- (Ctrl + R), paste
rundll32 sysdm.cpl,EditEnvironmentVariables
- under User Variables, double-click on Path> New> Paste copied path
- 获取安装节点模块的路径并复制到剪贴板
npm config get prefix | clip
- 没有剪辑?只需复制输出
npm config get prefix
- 将复制的路径添加到环境变量
- 我的首选方法(Windows)
- (Ctrl + R),粘贴
rundll32 sysdm.cpl,EditEnvironmentVariables
- 在用户变量下,双击路径>新建> 粘贴复制的路径