简体   繁体   English

在 Heroku 上部署 Express 应用程序错误:找不到模块“/app/server.js”

[英]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剩余一半的错误信息

File Tree文件树

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 指向一个不存在的文件。

Package.json Package.json

"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.

相关问题 部署到 Heroku 错误:找不到模块“/app/server.js” - Deployment to Heroku Error: Cannot find module '/app/server.js' 错误 [ERR_MODULE_NOT_FOUND]:找不到从 build\\server.js 导入的模块“build\\app” - Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'build\app' imported from build\server.js 错误:在谷歌应用引擎上部署 node.js 后找不到模块“/workspace/server.js” - Error: Cannot find module '/workspace/server.js' upon node js deploy on google app engine Docker 运行容器时出错 Error: Cannot find module '/home/app/server.js' - Docker error when running container Error: Cannot find module '/home/app/server.js' 错误:找不到模块'/opt/repo/ROOT/server.js - Error: Cannot find module '/opt/repo/ROOT/server.js 错误:找不到模块“/workspace/server.js” - Error: Cannot find module '/workspace/server.js' 节点 server.js 抛出错误 - 找不到模块 - Node server.js throws error - Cannot find module 错误:在server.js中找不到模块“ res” - Error: Cannot find module 'res' in server.js Docker NextJs ClientApp 的图像因错误无法找到模块“/app/server.js”而失败 - Docker Image for NextJs ClientApp failing with an error Cannot find module '/app/server.js' heroku /节点部署-找不到模块'app / dist / server / app.js' - heroku/node deployment - cannot find module 'app/dist/server/app.js'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM