VisualStudioCode终端出现->在此系统上禁止运行脚本

1、遇到的问题

json-server : 无法加载文件 D:\Program Files\nodejs\node_global\json-server.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Ex 
ecution_Policies。
+ json-server --watch --port 53000 db.json
+ ~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [],PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

2、解决方法

首先,一般刚学Vue,vscode的并没有安装node.js,和安装 json-server,这里只解决报错问题,安装教程直接可以在搜索框搜索,
1、打开vscode的之前,先使用管理员方式运行vscode,如下图所示
在这里插入图片描述
2、如果没安装json-server,需要先安装
教程在此: json-server安装
3、执行下方命令,显示Restricted,表示状态是禁止的

get-ExecutionPolicy

在这里插入图片描述
4、执行下方命令

set-ExecutionPolicy RemoteSigned;

5、最后在执行下方命令,显示RemoteSigned;

get-ExecutionPolicy

在这里插入图片描述

附件

在vscode终端操作过的报错及解决。

Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。

尝试新的跨平台 PowerShell https://aka.ms/pscore6

PS D:\code\Vue\vue3> npm install -g json-server
npm ERR! code EPERM
npm ERR! syscall open
npm ERR! path D:\Program Files\nodejs\node_cache\_cacache\tmp\f479a86b
npm ERR! errno EPERM
npm ERR! FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/json-server: EPERM: operation not permitted, open 'D:\Program Files\nodejs\node_cache\_cacache\tmp\f479a86b'
npm ERR!     at D:\Program Files\nodejs\node_modules\npm\node_modules\minipass-fetch\lib\body.js:162:15
npm ERR!     at async Arborist.[nodeFromEdge] (D:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1066:19)
npm ERR!     at async Arborist.[buildDepStep] (D:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:935:11)
npm ERR!     at async Arborist.buildIdealTree (D:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:216:7)
npm ERR!     at async Arborist.reify (D:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:149:5)
npm ERR!     at async Install.exec (D:\Program Files\nodejs\node_modules\npm\lib\commands\install.js:157:5)
npm ERR!     at async module.exports (D:\Program Files\nodejs\node_modules\npm\lib\cli.js:66:5)
npm ERR!  FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/json-server: EPERM: operation not permitted, open 'D:\Program Files\nodejs\node_cache\_cacache\tmp\f479a86b'
npm ERR!     at D:\Program Files\nodejs\node_modules\npm\node_modules\minipass-fetch\lib\body.js:162:15
npm ERR!     at async Arborist.[nodeFromEdge] (D:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1066:19)
npm ERR!     at async Arborist.[buildDepStep] (D:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:935:11)
npm ERR!     at async Arborist.buildIdealTree (D:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:216:7)
npm ERR!     at async Arborist.reify (D:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:149:5)
npm ERR!     at async Install.exec (D:\Program Files\nodejs\node_modules\npm\lib\commands\install.js:157:5)
npm ERR!     at async module.exports (D:\Program Files\nodejs\node_modules\npm\lib\cli.js:66:5) {
npm ERR!   code: 'EPERM',
npm ERR!   errno: 'EPERM',
npm ERR!   syscall: 'open',
npm ERR!   path: 'D:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\f479a86b',
npm ERR!   type: 'system',
npm ERR!   requiredBy: '.'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
PS D:\code\Vue\vue3> 

 Session contents restored from 2022/3/12 at 下午4:22:00 


尝试新的跨平台 PowerShell https://aka.ms/pscore6

PS D:\code\Vue\vue3> npm install -g json-server

added 176 packages, and audited 177 packages in 23s

  run `npm fund` for details

found 0 vulnerabilities
PS D:\code\Vue\vue3> $ json-server --watch --port 53000 db.json
$ : 无法将“$”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
所在位置 行:1 字符: 1
+ $ json-server --watch --port 53000 db.json
    + CategoryInfo          : ObjectNotFound: ($:String) [], CommandNotFoundException
 
PS D:\code\Vue\vue3> json-server --watch --port 53000 db.json
json-server : 无法加载文件 D:\Program Files\nodejs\node_global\json-server.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Ex 
ecution_Policies。
+ json-server --watch --port 53000 db.json
+ ~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [],PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
PS D:\code\Vue\vue3> get-ExecutionPolicy
Restricted
  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

所遇所思

你的鼓励将是我的原动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值