0

I have a file that works in local enviroment perfectly fine. But when i deploy it to Heroku it gets a build Error. The Heroku logs show me that it cannot find module request. I also took attention that the package.json is configured right: Package.json:

{
  "name": "nodejs - express - server",
  "version": "1.0.0",
  "description": "",
  "main": "proxy-request.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node proxy-request.js"
  },
  "keywords": [
    "example",
    "heroku"
  ],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.16.3",
    "request": "^2.87.0"
  },
  "engines": {
    "node": "8.11.2"
  }
}

And these are the packages i use in my proxy-request.js file:

const request = require('request');
const http = require('http');
const url = require('url');

1 Answer 1

1

When deploying Nodejs to Heroku, you create a file Procfile it run server file app.js, you can try the following after code

//package.json
{
  "name": "nodejs",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.18.2",
    "cheerio": "^1.0.0-rc.2",
    "ejs": "^2.5.7",
    "express": "^4.16.2",
    "mongodb": "^2.2.33",
    "mongoose": "^4.12.4",
    "nodemon": "^1.12.1",
    "path": "^0.12.7",
    "pg": "^6.1.0",
    "request": "^2.83.0",
    "request-promise": "^4.2.2",
    "router": "^1.3.2"
  }
}
//Procfile
web: node app.js

//app.js
var request = require("request");

Sign up to request clarification or add additional context in comments.

2 Comments

I have a procfile already that looks as follows: web: node proxy-request.js
you now try create a new project, after then,you is install moduel request ,you after then deploying to heroku see, if no error, you see again,only way

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.