我发布了自己的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编写的。

最佳答案

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

我想,在发布软件包时,npm以此方式构造程序

09-20 23:57