Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

node.js

npm

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

like image 875
Courage Avatar asked Dec 20 '16 13:12

Courage


People also ask

Can't find module after npm install?

To fix the Cannot find module error, simply install the missing modules using npm . This will install the project's dependencies into your project so that you can use them. Sometimes, this might still not resolve it for you. In this case, you'll want to just delete your node_modules folder and lock file ( package-lock.

Can not find module node path?

To solve the "Cannot find module path or its corresponding type declarations" error, install the types for node by running the command npm i -D @types/node . You can then import path with the following line of code import * as path from 'path' .


1 Answers

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.

like image 71
Joe Clay Avatar answered Oct 02 '22 12:10

Joe Clay