[英]Deployment of Express application on Heroku Error : Cannot find module '/app/server.js'
I've been trying to deploy my Express application on Heroku and the build gets created successfully but when I try to open it, I'm greeted with an error message that basically states that the page could not be served.我一直在尝试在 Heroku 上部署我的 Express 应用程序并且构建已成功创建,但是当我尝试打开它时,我收到一条错误消息,基本上指出无法提供该页面。
So, I run heroku logs --tail
and then I get the following error messages:因此,我运行
heroku logs --tail
然后收到以下错误消息:
One half of the error messages二分之一的错误信息
Remaining half of the error messages剩余一半的错误信息
Procfile
简介
web: node server.js
Package.json
Package.json
{
"name": "conduit-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.0.1",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"nodemon": "^2.0.12",
"pg": "^8.7.1",
"pg-hstore": "^2.3.4",
"redux-persist": "^6.0.0",
"sequelize": "^6.6.5"
},
"devDependencies": {
"cross-env": "^7.0.3"
}
}
server.js
服务器.js
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const { sequelize } = require('./src/entities/User/User');
const db = require('./src/config/Database');
const feedRoute = require('./src/routes/Feed/Feed');
const usersRoute = require('./src/routes/Users/Users');
const userRoute = require('./src/routes/User/User');
const articlesRoute = require('./src/routes/Articles/Articles');
const profilesRoute = require('./src/routes/Profiles/Profiles');
const commentsRoute = require('./src/routes/Comments/Comments');
const app = express();
app.use(cors());
app.use(bodyParser.json());
// Routes
app.use('/api/feed', feedRoute);
app.use('/api/users', usersRoute);
app.use('/api/user', userRoute);
app.use('/api/articles', articlesRoute);
app.use('/api/profiles', profilesRoute);
app.use('/api/articles', commentsRoute);
// REQUESTS
app.get('/', async (req,res) => {
res.json('Yooooooooooo')
try {
await db.authenticate();
console.log('Connection has been established');
} catch(err) {
console.log('Error');
}
})
// To START sequelize and also wipes the DB clean
// async function main() {
// await sequelize.sync({force: true})
// }
// main()
// TO START sequelize
const PORT = process.env.PORT || 3000;
app.listen(PORT , () => {
console.log(`App is listening to ${PORT}`);
})
I've tried modifying my procfile and removing and re-installing the modules but the problem still persists.我已经尝试修改我的 procfile 并删除并重新安装模块,但问题仍然存在。
I've been stuck on this for days now and any sort of help would be highly appreciated.我已经坚持了好几天了,非常感谢任何形式的帮助。
Looks like you problem is your pointing the main in package.json
to a file that doesn't exist.看起来你的问题是你将
package.json
中的 main 指向一个不存在的文件。
"main": "index.js"
Your app seems to deploy from you server.js
file.您的应用程序似乎是从您的
server.js
文件部署的。
The main
field is a module ID that is the primary entry point to your program. main
字段是一个模块 ID,它是程序的主要入口点。 as per documentation:https://docs.npmjs.com/cli/v7/configuring-npm/package-json#main根据文档:https://docs.npmjs.com/cli/v7/configuring-npm/package-json#main
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.