简体   繁体   中英

npm publish node.js module and yet can not find module after npm install

thanks your time advance.

first, I publish npm package success.(verified that already in the npmjs.com profile, the package name I can call 'firstnpmpublish'(uniqueness))

second, write require('firstnpmpublish') in my test.js file and type npm install firstnpmpublish

third , type node test.js in the terminal on my mac. but it print:

    throw err;
    ^

Error: Cannot find module 'firstnpmpublish'

I have tried 'npm install firstnpmpublish' and 'npm install firstnpmpublish -g' and also 'npm install' as I create package.json which dependencise include firstnpmpublish. but it still doesn't work.

however, instead of require('firstnpmpublish') and using require('express'),it work smoothly.

where i was wrong? thanks

Your package.json file doesn't specify the path to your main file, so the require can't be resolved. Add the following to your package.json and then republish:

"main": "Print.js"

I'd recommend renaming that file to index.js though, to better fit with the Node conventions.

I had a very similar issue. Removing the entire node_modules folder and re-installing worked for me:

rm -rf node_modules
npm install

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM