TypeScript

运行tsc命令时报错

  • 错误信息

tsc : 无法加载文件 C:\Users\Administrator\AppData\Roaming\npm\tsc.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 1

  • 解决方式

1: win + x 启动 windows PowerShell(管理员)

2: 输入命令,敲回车

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

3: 提示输入内容时,输入Y ,再敲回车即可

npm uninstall -g typescript
npm uninstall -g ts-node
npm cache verify

npm install -g typescript@4.4.4
npm install -g ts-node@10.0.0

tsc -v
ts-node -v
  • 运行js

tsc hello.ts 会生成一个hello.js文件

node hello.js

  • 运行ts

ts-node hello.ts

npm淘宝源

npm config get registry
https://registry.npmjs.org/

npm config set registry https://registry.npm.taobao.org

生成配置文件

tsc --init

posted @ 2022-08-18 09:50  hellsino  阅读(13)  评论(0编辑  收藏  举报