为什么找不到我自己的自定义模块?

时间:2017-02-25 09:05:29

标签: javascript node.js npm ecmascript-6

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

这是我的模块

target folder inside which war is present

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

我做了什么。

$ 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编写的。

1 个答案:

答案 0 :(得分:1)

node_modules内找到包kong-hmac,你发现lib文件夹不是src,而是在kong-hmac package.json更改"main": "src/index.js" } "main": "lib/index.js"

我想,虽然发布一个包npm以这种方式构建程序