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
posted @   所遇所思  阅读(469)  评论(0编辑  收藏  举报  
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
🔑
  1. 1 404 not found REOL
  2. 2 偏爱 张芸京
  3. 3 Glimpse of Us Joji
偏爱 - 张芸京
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作词 : 葛大为

作曲 : 陈伟

编曲 : 陈伟

把昨天都作废

现在你在我眼前

我想爱 请给我机会

如果我错了也承担

认定你就是答案

我不怕谁嘲笑我极端

相信自己的直觉

相信自己的直觉

顽固的人不喊累

爱上你 我不撤退

我说过 我不闪躲

我说过 我不闪躲

我非要这么做

讲不听 也偏要爱

更努力爱 让你明白

没有别条路能走

你决定要不要陪我

讲不听 偏爱

靠我感觉爱

等你的依赖

对你偏爱

痛也很愉快

把昨天都作废

把昨天都作废

现在你在我眼前

我想爱 请给我机会

如果我错了也承担

认定你就是答案

我不怕谁嘲笑我极端

相信自己的直觉

相信自己的直觉

顽固的人不喊累

爱上你 我不撤退

我说过 我不闪躲

我说过 我不闪躲

我非要这么做

讲不听 也偏要爱

更努力爱 让你明白

没有别条路能走

你决定要不要陪我

讲不听 偏爱

靠我感觉爱

等你的依赖

不后悔 有把握

不后悔 有把握

我不闪躲 我非要这么做

讲不听 也偏要爱

更努力爱 让你明白

没有别条路能走

你决定要不要陪我

讲不听 偏爱

靠我感觉爱

等你的依赖

对你偏爱 爱

痛也很愉快