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
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.
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' .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With