node.js on heroku: Error: Cannot find module 'csv'

Problem

I'm using a common node package 'csv' to do CSV parsing. It works great on my local mac, but not on heroku. In the "heroku log", I get Cannot find module 'csv'.

Yes, I have it in my package json file:

{
    "name":"rimes",
    "version":"0.0.1",
    "dependencies":{
    "sys":"",
    "url":"",
    "http":"",
    "querystring":"",
    "oauth":"0.9.10",
    "fs":"",
    "csv":"0.3.0",
    "request":"",
    "node-cache":"",
    "underscore":""
    }
}

and I require it in my app.js

var sys = require('sys'),
http = require('http'),
url = require('url'),
qs = require('querystring'),
OAuth= require('oauth').OAuth,
fs = require('fs'),
csv = require('csv'),
myreq = require('request'),
NodeCache = require('node-cache'),
us = require('underscore');

What can I do to fix this on heroku?

Thank you, ~Todd

Problem courtesy of: Todd Rimes

Solution

So when you require packages on node, you also need to install them in your node_modules folder. They must be in the node_modules folder as well as "required" in your code. They can only be declared in your "package.json."

If you go into your project directory (the file where package.json is located) and run:

npm install

it should install your missing dependencies into your 'node_modules' folder.

Then if you re-deploy your app to heroku it should work.

Solution courtesy of: yvanscher

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.