执行npm install -g json-server 命令报错

执行npm install -g json-server 命令报错

npm ERR! code ETIMEDOUT
npm ERR! syscall connect
npm ERR! errno ETIMEDOUT
npm ERR! network request to https://registry.npmjs.org/json-server failed, reason: connect ETIMEDOUT 104.16.22.35:443
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'








npm ERR! code EPERM
npm ERR! syscall mkdir
npm ERR! path E:\DISK\document\windowsSoftware\javaTools\Node\node_global
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, mkdir 'E:\DISK\document\windowsSoftware\javaTools\Node\node_global'
npm ERR!  [Error: EPERM: operation not permitted, mkdir 'E:\DISK\document\windowsSoftware\javaTools\Node\node_global'] {
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: 'E:\\DISK\\document\\windowsSoftware\\javaTools\\Node\\node_global'
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! network request to https://registry.npmjs.org/json-server failed, reason: connect ETIMEDOUT 104.16.16.35:443

上面的错误一共是分为了两类,一类是访问https://registry.npmjs.org/json-server failed这个地址的时候失败,可能是这个地址是在国外吧,就跟我去node.js官网下载软件多次下载失败一样, 还有一类错误是没有权限访问node_global这个文件夹,这个文件夹在哪里呢,就是在安装的node.js文件下,如果没有的话可以自己新建一个,然后再给这个文件夹设置权限.

先说给文件夹设置权限的问题,右键属性选择安全,点击编辑,然后给所有的组或用户名勾选完全控制的权限.

image-20230514002433379

另外一种错误是访问地址失败,请求连接超时,(今天学习axios时,使用 json-server 搭建 REST API。需要npm install -g json-server, 在vscode中执行npm install -g json-server,安装进度条走了一半时报错)

是否是网络问题?然后npm config list查看下镜像地址:

找这哥镜像地址

image-20230514002806420

然后输入一遍后没有找到,提示再使用以下命令查看全部npm config ls -l

image-20230514002739670

找到

image-20230514002920082

用的是npm官方服务器,随后执行下面命令:
npm config set registry https://registry.npm.taobao.org/
npm config get registry https://registry.npm.taobao.org/
切换为淘宝镜像,以上两条命令都要执行

image-20230514003009425

修改成了

然后再次执行json -server 安装命令就可以了.

image-20230514003056658

感谢,参考文章:https://blog.csdn.net/lianghongyu2019/article/details/113092551

posted @ 2023-05-14 00:32  哩个啷个波  阅读(567)  评论(0编辑  收藏  举报