NPM本地install报错code E404 404Not Found - GET https://registry.npmjs.com/xxxx - Not found

npm install命令既可以下载服务器上的模块,也可以在本地创建自己的模块。

当在本地创建模块的是,需要指定目录,否则install会默认去服务器上下载。
这时候一般会下载失败,报错如下:

49 verbose node v16.13.1
50 verbose npm  v8.1.2
51 error code E404
52 error 404 Not Found - GET https://registry.npmjs.com/xxxx - Not found
53 error 404
54 error 404 'xxxx@*' is not in this registry.
55 error 404 You should bug the author to publish it (or use the name yourself!)
56 error 404 Note that you can also install from a
57 error 404 tarball, folder, http url, or git url.
58 verbose exit 1

本地创建模块步骤如下(nodejs文件存放在testmd目录下:):

> cd testmd
> ls
testmd.js
> npm init --yes  #生成package.json文件,这个是创建模块必备文件
Wrote to E:\nodejs\testmd\package.json:

{
  "name": "testmd",
  "version": "1.0.0",
  "description": "",
  "main": "testmd.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
> ls
package.json
testmd.js
> cd ..   #跳到上级目录
> npm install ./testmd
added 1 package, and audited 5 packages in 2s

found 0 vulnerabilities

> ls #打出以上日志表示创建成功。模块安装在node_modules目录下
testmd
node_modules

本地创建成功后,还可以将模块发布到服务器上。目前所有的模块都是发布到https://www.npmjs.com/。发布前需要注册和激活一个账户。

激活后在模块目录下执行发布命令即可:

> npm publish
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值