Heroku - 构建错误 - 找不到模块请求
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Heroku - 构建错误 - 找不到模块请求相关的知识,希望对你有一定的参考价值。
我有一个在本地环境中工作的文件完全没问题。但是当我将它部署到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');
答案
在将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");
以上是关于Heroku - 构建错误 - 找不到模块请求的主要内容,如果未能解决你的问题,请参考以下文章
部署到 Heroku 错误:找不到模块“/app/server.js”