I forked an npm package (https://github.com/spark/particle-api-js), made some changes, used that in a project (https://github.com/RoomKit/RoomKit-Backend) and then left it for a while.
I resumed working on it today and suddenly node claims that the package is not installed. If I replace my custom repo in package.json with a version number it works just fine. In both cases the package is there in the node_modules folder.
I deleted the node_modules folder and ran npm install
. That goes through without a problem but at runtime it still complains. What is going on?
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' .
If you are getting the "Cannot find module" error when trying to run a local file, make sure that the path you passed to the node command points to a file that exists. For example, if you run node src/index. js , make sure that the path src/index. js points to an existing file.
If you're installing from a forked package on github you are probably missing the lib
directory for the package. NPM doesn't run a build on forked packages so it's not going to be there if you do npm install. You can verify this by going into the node_modules
directory, finding your package's directory and checking for what's in there. Simply having a src
folder is not enough.
One way around this is to make sure your forked repo checks in any build
or lib
folders.
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