【问题标题】:Why Cannot find my own custom module?为什么找不到我自己的自定义模块?
【发布时间】:2017-02-25 09:05:28
【问题描述】:

我发布了自己的 npm 模块,但在我的示例脚本中找不到它。

这是我的模块

https://www.npmjs.com/package/kong-hmac

https://github.com/y-zono/kong-hmac-js

我做了什么。

$ mkdir /tmp/sample-myjs
$ cd /tmp/sample-myjs/
$ touch package.json
$ echo "{}" > package.json
$ npm install --save kong-hmac
$ npm install --save-dev babel-cli
$ npm install --save-dev babel-preset-es2015
$ touch test.js
$ echo 'const hmac = require("kong-hmac");' > test.js
$ babel-node --presets es2015 test.js 
module.js:327
    throw err;
    ^

Error: Cannot find module 'kong-hmac'

有什么想法吗?我的模块是用 ES2015 编写的。

【问题讨论】:

  • 我发现了问题

标签: javascript node.js npm ecmascript-6


【解决方案1】:

在您的node_modules 中查找包kong-hmac,您会找到lib 文件夹而不是src,并且在kong-hmac 的package.json 中将"main": "src/index.js" 更改为"main": "lib/index.js"。

我猜,在发布包时,npm 会以这种方式构建程序

【讨论】:

  • 谢谢。我现在正在做。
  • 成功了。你是完全正确的。谢谢你。你救了我!
  • 酷。我会用它作为参考
猜你喜欢
  • 2019-07-08
  • 1970-01-01
  • 2022-01-17
  • 1970-01-01
  • 2017-06-29
  • 1970-01-01
  • 2019-05-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多