javascript - 在 npm 注册表中安装我发布的包时出错 - Errorno - 4058。没有这样的文件或目录 main.js 错误

标签 javascript node.js npm npm-install

我创建了一个示例包并将其发布到我自己的 npm 帐户下的 npm 注册表中。我的包的名称是 newtestmay。现在,当我尝试使用命令 npm install newtestmay 安装它时,出现以下错误。我已从 npm-debug.log 文件中复制了整个日志中的错误级别日志,该文件是由 npm 在我尝试安装包的根目录中创建的:

128 error Windows_NT 6.1.7601

129 error argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" "newtestmay"

130 error node v6.9.1

131 error npm v3.10.8

132 error path D:\rbt\math_user\node_modules\newtestmay\main.js

133 error code ENOENT

134 error errno -4058

135 error syscall chmod

136 error enoent ENOENT: no such file or directory, chmod 'D:\rbt\math_user\node_modules\newtestmay\main.js'

137 error enoent ENOENT: no such file or directory, chmod 'D:\rbt\math_user\node_modules\newtestmay\main.js'

137 error enoent This is most likely not a problem with npm itself

137 error enoent and is related to npm not being able to find a file.

138 verbose exit [ -4058, true ]

我发布的 newtestmay 包的

package.json:

{
  "name": "newtestmay",
  "version": "1.0.0",
  "description": "an example of creating a package",
  "main": "bin/main.js",
  "bin": {
    "mathexample22may": "main.js"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "math",
    "example",
    "addition",
    "subtraction",
    "multiplication",
    "division",
    "fibonacci"
  ],
  "author": "rasik210",
  "license": "ISC"
}

我的包的目录结构:

enter image description here

main.js的代码:

var path = require('path');
var fs = require('fs');
var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib');
var simple = require(lib + '/simple_math.js');
var advanced = require(lib + '/advanced_math.js');
module.exports = {
addition: simple.addition,
subtraction: simple.subtraction,
multiplication: advanced.multiplication,
division: advanced.division,
fibonacci: advanced.fibonacci
}

我无法理解为什么 NPM 无法看到我发布包时 bin 目录中存在的 main.js

最佳答案

简单的拼写错误:package.jsonbin 对象都是相对于项目的根目录的。在这种情况下,它应该是:

{
    ...
    "bin": {
      "mathexample22may": "./bin/main.js"
    },
    ...
}

关于javascript - 在 npm 注册表中安装我发布的包时出错 - Errorno - 4058。没有这样的文件或目录 main.js 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44125235/

相关文章:

javascript - 使用node.js从数据库获取数据

javascript - 菜单要固定在滚动条的顶部

node.js - 如何动态更改 Mongoose 提供程序中集合或数据库的名称,Nestjs?

javascript - 如何在 React 或 Next.js 中使用绝对路径而不是相对路径?

javascript - 使用 JavaScript 设置 HTML 页面垂直位置

javascript - 在 Object Orient JS 中,我试图动态地将一个对象添加到数组中

javascript - 控制台时间(秒)

javascript - 用户登录时 Iron.seal 不起作用

amazon-web-services - 当您拥有私有(private) NPM 包时,如何使用 CLI 部署到 Elastic Beanstalk?

laravel - 如何修复laravel 6中的错误npm run dev