Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Error: Cannot find module' after fork and patch

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?

like image 947
Mak Avatar asked Jan 20 '17 01:01

Mak


People also ask

How do I resolve Cannot find module error using node JS?

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 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' .

Can not find module index JS?

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.


1 Answers

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.

like image 86
Eddy Borja Avatar answered Sep 20 '22 19:09

Eddy Borja