[英]Why Cannot find my own custom module?
I published my own npm module but it cannot find from my sample script. 我发布了自己的npm模块,但无法从示例脚本中找到。
This is my module 这是我的模块
https://www.npmjs.com/package/kong-hmac https://www.npmjs.com/package/kong-hmac
https://github.com/y-zono/kong-hmac-js https://github.com/y-zono/kong-hmac-js
What I did. 我做了什么。
$ 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'
Any ideas? 有任何想法吗? My module is written in ES2015. 我的模块是用ES2015编写的。
Inside your node_modules
look for the package kong-hmac
you find lib
folder not src
and in the package.json
of kong-hmac change "main": "src/index.js"
to "main": "lib/index.js"
. 在您的node_modules
内部,查找kong-hmac
软件包,找到lib
文件夹而不是src
然后在kong-hmac的package.json
中将"main": "src/index.js"
更改为"main": "lib/index.js"
。
I guess, while publish a package npm structures the program this way 我想,在发布软件包时,npm以此方式构造程序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.