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
本文来自博客园,作者:所遇所思,转载请注明原文链接:https://www.cnblogs.com/mynxg/p/17989337