Error: Cannot find module './proto' on Heroku - node.js

I can't seem to figure out why this works locally fine, but when I push it to Heroku it fails with the following error.
Error from Heroku
Starting process with command `node web.js`
module.js:337
throw new Error("Cannot find module '" + request + "'");
^
Error: Cannot find module './proto'
at Function._resolveFilename (module.js:337:11)
at Function._load (module.js:279:25)
at Module.require (module.js:359:17)
at require (module.js:375:17)
at Object.<anonymous> (/app/node_modules/express/node_modules/connect/lib/connect.js:14:13)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Module.require (module.js:359:17)
Process exited with status 1
State changed from starting to crashed
package.json
{
"name": "divtest",
"version": "0.0.2",
"dependencies": {
"underscore": "1.3.x",
"crypto": "0.0.x",
"knox": "0.3.x",
"mongoose": "~3.1.2",
"mime": "1.2.x",
"express": "3.0.x",
"request": "~2.9.203"
},
"engines": {
"node": "0.6.x",
"npm": "1.0.x"
}
}
./proto is a local module that connect is calling
I've blown away my ./node_modules folder and did a npm install --save and still get the same results.

I had this issue, and my problem was that I'm a git beginner and hadn't properly committed all of the files that were needed. It looks like there was a proto.js in connect somewhere.
I did a git add * (...) and pushed again and it all went nicely.
Another telling error, was that on push Heroku complained about unmet dependencies.

Related

Node cannot find installed package

I have a simple nodejs client that uses grpc and protobuf to talk to a cpp grpc server.
My package.json contains the required packages:
"dependencies": {
"google-protobuf": "^3.9.1",
"grpc-web": "^1.0.6",
"webpack": "^4.39.2",
"webpack-cli": "^3.3.7"
}
I ran npm install and all the modules were installed in locally node_modules.
My client in in the same path as node_modules but when I launch it, I get an error saying that it cannot find the protobuf module.
From client.js:
var messages = require('../../messages/proto/output/work_pb.js');
var services = require('../../messages/proto/output/work_grpc_web_pb.js');
var grpc = require('grpc');
Running the client:
node client.js
Error: Cannot find module 'google-protobuf'
Require stack:
- /home/work/messages/proto/output/work_pb.js
- /home/work/frontend/web/client.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:713:15)
at Function.Module._load (internal/modules/cjs/loader.js:618:27)
at Module.require (internal/modules/cjs/loader.js:771:19)
at require (internal/modules/cjs/helpers.js:68:18)
at Object.<anonymous> (/home/radu/work/admass/messages/proto/output/work_pb.js:11:12)
at Module._compile (internal/modules/cjs/loader.js:868:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:879:10)
at Module.load (internal/modules/cjs/loader.js:731:32)
at Function.Module._load (internal/modules/cjs/loader.js:644:12)
at Module.require (internal/modules/cjs/loader.js:771:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/work/messages/proto/output/work_pb.js',
'/home/work/frontend/web/client.js
Removing the entire node_modules folder and re-installing will work:
rm -rf node_modules
npm install
I ended up adding the node module inside '../../messages/ and removing it from pace where the proto files are being referenced, as to avoid conflicts.

Cannot find module './mergeConfig' when running on Heroku

I have a node application that runs fine when executed on my machine via node my_application.js.
However, if push it to heroku and execute it via heroku run node my_application.js or with the scheduler what I get is this error:
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module './mergeConfig'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/app/node_modules/axios/lib/core/Axios.js:7:19)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
I'm running node v10.16.0 and npm v6.9.0 both locally and on Heroku, so I really don't know what may be causing this issue, and googling for it didn't help in any way.
Any ideas about this mergeConfig module that seems to be missing from my heroku environment but not from my local environment?
Edit: this is my package.json:
{
"name": "[REDACTED]",
"version": "1.0.0",
"description": "[REDACTED]",
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.19.0",
"bluebird": "^3.5.3",
"body-parser": "^1.18.3",
"dateformat": "^3.0.3",
"express": "^4.16.4",
"form-data": "^2.3.3",
"http-to-curl": "^1.4.2",
"jest": "^24.8.0",
"qs": "^6.6.0",
"querystring": "^0.2.0",
"redis": "^2.8.0",
"simple-oauth2": "^2.2.1"
}
}
Try to add explicitly the missing module in the dependencies in package.json:
"dependencies": {
...
"merge-config" :"2.0.0"
...
}
I think it works on your local environment because you have the module installed globally.
I had the same problem.
'./mergeConfig' is a file inside de axios module.
Path: node_modules/axios/core/mergeConfig.js
For some reason heroku had a problem with this file.
I solved it by replacing axios with request.
This fixed the problem for me NODE_OPTIONS=--max_old_space_size=4096
src: https://github.com/axios/axios/issues/1767#issuecomment-416924946

error deploying node.js app to heroku

I'm trying to deploy my node.js app to heroku.
I'm getting this error on git push heroku master:
> on-headers#1.0.1 test /tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/response-time/node_modules/on-headers
> mocha --reporter spec --bail --check-leaks test/
/tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/mocha/lib/utils.js:626
throw new Error("cannot resolve path (or pattern) '" + path + "'");
^
Error: cannot resolve path (or pattern) 'test/'
at Object.lookupFiles (/tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/mocha/lib/utils.js:626:15)
at /tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/mocha/bin/_mocha:316:30
at Array.forEach (native)
at Object.<anonymous> (/tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/mocha/bin/_mocha:315:6)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:136:18)
at node.js:963:3
> node-statsd#0.1.1 test /tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/soluto-monitor/node_modules/node-statsd
> mocha -R spec
/tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/mocha/lib/utils.js:626
throw new Error("cannot resolve path (or pattern) '" + path + "'");
^
Error: cannot resolve path (or pattern) 'test'
at Object.lookupFiles (/tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/mocha/lib/utils.js:626:15)
at /tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/mocha/bin/_mocha:316:30
at Array.forEach (native)
at Object.<anonymous> (/tmp/build_4d6fe429e576b4e42425b713c87264e9/node_modules/mocha/bin/_mocha:315:6)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:136:18)
at node.js:963:3
...
..and on and on with the error Error: cannot resolve path (or pattern) 'test/' for each node_modules subdirectory.
my package.json looks like more or less like this:
{
"name": "my-module",
"version": "0.1.0",
"description": "My Module",
"dependencies": {
"azure-storage": "0.6.0",
"bluebird": "3.0.6",
"body-parser": "1.14.1",
"cors": "2.7.1",
"dotenv": "^1.2.0",
"express": "3.3.3",
"moment": "2.10.6",
"request-promise": "1.0.2",
"rx": "4.0.7",
"shisell": "0.0.2",
"striptags": "2.0.4",
"winston": "2.1.1"
},
"devDependencies": {
"chai": "^3.4.1",
"chai-as-promised": "^5.1.0",
"mocha": "^2.3.4",
"mock-require": "^1.2.1",
"sinon": "^1.17.2",
"sinon-chai": "^2.8.0",
"supertest": "^1.1.0"
},
"main": "server.js",
"engines": {
"node": "4.2.3"
},
"scripts": {
"test": "mocha"
}
}
it seems like mocha is trying to run from within node_modules, inside each dependency. i managed to reproduce the error locally by running mocha from within one of the node_modules directories.
I tried removing test script from my package.json and I still get the same error.
I'm new to heroku deployments. As far as I understood once I git push to heroku then heroku runs npm install and if there is a test script it will run. But I don't understand what causes it to try and run mocha within subdirectories of node_modules (and why that would happen even if I don't specify a test script inside my package.json).
Any ideas?
p.s. this doesn't happen when I run locally on my machine.
Turns out I had this environment variable set: NPM_CONFIG_NPAT=true on heroku and it causes npm to run tests on all the installations, as described here:
https://docs.npmjs.com/misc/config#npat

ORMError NO_SUPPORT: Connection protocol not supported - have you installed the database driver for postgres?

I'm trying to deploy a nodejs application on ubuntu 13.10. I have tested it on my local mac( working good).
But when I try to run it on my ubuntu server, i got this:
[ORMError NO_SUPPORT: Connection protocol not supported - have you installed the database driver for postgres?]
at Object.exports.connect (/home/ubuntu/node_modules/orm/lib/ORM.js:138:21)
at Object.module.exports (/home/ubuntu/node_modules/orm/lib/Express.js:12:6)
at Object.exports.express (/home/ubuntu/node_modules/orm/lib/ORM.js:39:30)
at Object.<anonymous> (/home/ubuntu/www/sher/nodejs/app.js:30:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
error: Forever detected script exited with code: 8
FYI:
I installed npm install pg after i got this error, but didn't work.
I also instadded postgresql9.1 with sudo apt-get install build-essential postgresql-9.1 postgresql-server-dev-9.1 libxml2-dev libproj-dev libjson0-dev xsltproc docbook-xsl docbook-mathml.
Anyone can suggest any idea whats going on here?
Thank you!
{
"name": "nodejs",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"express": "~4.2.0",
"static-favicon": "~1.0.0",
"morgan": "~1.0.0",
"cookie-parser": "~1.0.1",
"body-parser": "~1.0.0",
"debug": "~0.7.4",
"jade": "~1.3.0"
}
}
I just reinstalled all packages and modules again one by one. Seems fixed the problem.

Dependencies issue on dotCloud

I have an issue while deploying my nodejs app on dotCloud regarding the dependencies. This app use node-canvas (https://github.com/LearnBoost/node-canvas) to generate a thumbnail of the sheet music (related to the music sheets available on jellynote.com).
I don't have any error during the push of my application and the installation of the dependencies. Here is my package.json file:
{
"name": "jellyscore",
"version": "1.0.0",
"dependencies": {
"canvas": "",
"mongodb": ""
}
}
and here is the logs that dotCloud return (edited log):
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module '../build/default/canvas'
at Function._resolveFilename (module.js:326:11)
at Function._load (module.js:271:25)
at require (module.js:355:19)
at Object.<anonymous> (/home/dotcloud/node_modules/canvas/lib/bindings.js:7:20)
at Module._compile (module.js:411:26)
at Object..js (module.js:417:10)
at Module.load (module.js:343:31)
at Function._load (module.js:302:12)
at require (module.js:355:19)
at Object.<anonymous> (/home/dotcloud/node_modules/canvas/lib/canvas.js:12:14)
Thanks!
Have you added CAIRO as system dependency ?
in you dotCloud yml:
systempackages:
- libcairo2
So if you have a Node.js only app it should look like this:
www:
type: nodejs
systempackages:
- libcairo2

Resources