Home > Enterprise >  Heroku Cannot find module 'request'
Heroku Cannot find module 'request'

Time:04-02

Bare bones Nodejs app works locally. Package.json modified per Heroku. Get error when deployed.

My second Heroku deploy. Took Heroku Sample app, deployed successfully, then modified Sample to have simple js - outlined as follows:

require mongoose, express, body-parser, request then

app.get("/", function(req, res) {res.sendFile(__dirname   "/register.html");});

Modified sample as above to make app a little more similar to what I eventually want to deploy.  Modified "package.json" to have:

"name": 
    "js-getting-started",
    "version": "0.3.0",
    "description": "A sample Node.js app using Express 4",
    "engines": {"node": "16.x"},
"dependencies": {
    "express": "^4.17.3",
    "mongoose" : "^6.2.5",
    "mongodb": "^4.2.0","body-parser": 
    "^1.19.0"},
    "devDependencies": {"got": "^11.3.0","tape": "^4.7.0"
},

Undoubtedly remote and local environments not in synch. Set Node version to 16.x and 16.14.0 -- still get error.

CodePudding user response:

request is a NPM module. Add the module to your dependencies by running npm install --save request.

request will be added in dependencies like this:

{
  "name": "js-getting-started",
  "version": "0.3.0",
  "description": "A sample Node.js app using Express 4",
  "engines": {"node": "16.x"},
  "dependencies": {
    "request": "^2.83.0",
    "express": "^4.17.3",
    "mongoose" : "^6.2.5",
    "mongodb": "^4.2.0",
    "body-parser": "^1.19.0"
  },
  "devDependencies": {
    "got": "^11.3.0",
    "tape": "^4.7.0"
  }
}

Source: https://www.npmjs.com/package/request

CodePudding user response:

As of February 11, 2020, one of the biggest NPM packages — Request — has been officially deprecated

You may use node-fetch instead. https://www.npmjs.com/package/node-fetch

For that you need to add this package in you app root directory

npm i --save node-fetch

  • Related