node.js无法访问npm等一系列问题

命运对每个人都是一样的,不一样的是各自的努力和付出不同,付出的越多,努力的越多,得到的回报也越多,在你累的时候请看一下身边比你成功却还比你更努力的人,这样,你就会更有动力。

导读:本篇文章讲解 node.js无法访问npm等一系列问题,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

2023/4/11日晚遇到的问题

1、问题一

‘CALL “I:\Program Files\nodejs\node.exe” “I:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js”
在这里插入图片描述
解决方法:
把环境配置变量里面的 ComSpec删掉就行了
删掉后
在这里插入图片描述
环境变量配置我的电脑右击->属性

在这里插入图片描述
在这里插入图片描述

删掉这个 comspec
在这里插入图片描述

2、解决完又出现第二个问题

— json-server : 无法加载文件xx\npm\json-server.ps1,因为在此系统上禁止运行脚本
在这里插入图片描述

解决方法:
使用管理员方式打开Power Shell
输入Get-ExecutionPolicy,可以查看到当前的策略
输入Set-ExecutionPolicy RemoteSigned,设置当前的策略为RemoteSigned
输入Y
在这里插入图片描述

3、报错:json-server Type of “xxx” (string) is not supported.

会报错: json-server Type of “name” (string) is not supported.
原因与json-server的工作方式有关
直接暴露在JSON对象根目录下的每个键都被视为json-server中的单独URL。
需要使用对象或数组对象

{
   "username": [
      {
         "name": "zwy",
         "id":1
      },
      {
         "name": "zs",
         "id":2
      }
   ]
}
//最外层需要定义一个对象或者数组对象

解决后


PS G:\前端开发\ajax> json-server .\1.json --watch

  \{^_^}/ hi!     

  Loading .\1.json
  Done

  Resources
  http://localhost:3000/username

  Home
  http://localhost:3000

  Type s + enter at any time to create a snapshot of the database
  Watching...

Some error occurred Error: listen EADDRINUSE: address already in use ::1:3000
    at Server.setupListenHandle [as _listen2] (node:net:1740:16)
    at listenInCluster (node:net:1788:12)
    at GetAddrInfoReqWrap.doListen [as callback] (node:net:1937:7)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:109:8) {
  code: 'EADDRINUSE',
  errno: -4091,
  syscall: 'listen',
  address: '::1',
  port: 3000
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/144066.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!