Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node jitsu cannot find local modules

I have an application successfully working locally so I know the code works. However when I go to deploy to node jitsu I get an error that it cannot find a local module. Here is what I have:

File Setup:

/index.js
/config/config.js

index.js

var cfg = require('./config/config.js');

When trying to deploy node jitsu is giving me an error:

Error: Cannot find module './config/config.js'

Since all this code works locally I do not believe this is a coding issue. I am under the impression that local modules do not need to be included in package.json but perhaps they do for node jitsu? I read their documentation but cannot find anything special for local modules.

Thanks!

like image 890
nwkeeley Avatar asked Dec 02 '12 16:12

nwkeeley


People also ask

How to fix Cannot find module?

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.

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

Can not find module npm?

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.


2 Answers

Local modules like this should work properly.. so long as you don't have it in .gitignore or .npmignore.

Modules in the node_modules directory require that you add it to the bundledDependencies array in your package.json file.

An easy way to check for whether the file is included in your deploy is to run tar -tf $(npm pack).

like image 54
Sly Avatar answered Oct 17 '22 00:10

Sly


I had this exact same error on deploy, but caused by a different root cause. In case anybody stumbles into the same problem:

File Setup:

/public/Data/TargetData.js

app.js require statement:

var target = require('./public/data/TargetData.js');

My local Mac OSX environment allowed the capitalization difference of /data/ vs. /Data/ - the Nodejitsu server did not.

like image 41
KTys Avatar answered Oct 16 '22 22:10

KTys