Heroku-构建错误-找不到模块请求

时间:2018-06-29 09:49:14

标签: node.js heroku deployment

我有一个在本地环境下可以正常工作的文件。但是,当我将其部署到Heroku时,会出现构建错误。 Heroku日志显示无法找到模块请求。我还注意到package.json的配置正确: 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"
  }
}

这些是我在proxy-request.js文件中使用的软件包:

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

1 个答案:

答案 0 :(得分:0)

在将Nodejs部署到Heroku时,创建一个文件Procfile并运行服务器文件app.js,可以在代码后尝试以下操作

//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");