簡體   English   中英

在 Heroku 上部署 NodeJS 應用程序時遇到錯誤

[英]Facing errors to deploy NodeJS app on Heroku

我正在嘗試部署我的 nodejs 應用程序,但它給了我這個錯誤:

2019-11-25T18:16:16.927748+00:00 app[web.1]: > anonymous-forum-discussion@1.0.0 start /app
2019-11-25T18:16:16.927751+00:00 app[web.1]: > nodemon server.js
2019-11-25T18:16:16.927753+00:00 app[web.1]:
2019-11-25T18:16:16.935126+00:00 app[web.1]: sh: 1: nodemon: not found
2019-11-25T18:16:16.940397+00:00 app[web.1]: npm ERR! file sh
2019-11-25T18:16:16.940690+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-11-25T18:16:16.940929+00:00 app[web.1]: npm ERR! errno ENOENT
2019-11-25T18:16:16.941180+00:00 app[web.1]: npm ERR! syscall spawn

我嘗試了 StackOverflow 上發布的其他可能的解決方案,但似乎根本不起作用。 每次部署我的 nodejs 應用程序時,我都會收到一個Application Error

我的package.json文件:

{
  "name": "anonymous-forum-discussion",
  "version": "1.0.0",
  "description": "Anonymous Forum Discussion",
  "main": "server.js",
  "scripts": {
    "start": "nodemon server.js",
    "test": "echo \"Error: no test specified\" && exit 1",
    "postinstall": "cd frontend && npm install && npm run build && cd .."
  },
  "dependencies": {
    "body-parser": "^1.19.0",
    "express": "^4.17.1",
    "mongoose": "^4.11.5"
  },
  "devDependencies": {
    "nodemon": "^1.19.4"
  },
  "engines": {
    "node": "10.15.3"
  }
}

我的Procfile : web: node server.js

我的server.js代碼:

var express = require('express');
const path = require('path');

var mongoose = require('mongoose');
var bodyParser = require('body-parser');

var models = require('./api/models/message');

var routes = require('./api/routes/routes');

var port = process.env.PORT || 3001;
var app = express();
var Message = mongoose.model('Message')

mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost/discussion');

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

routes(app);

if (process.env.NODE_ENV === "production") {
  app.use(express.static("frontend/build"));
  console.log("production");
}

app.get('*', function (request, response){
  response.sendFile(path.resolve(__dirname, 'frontend/build', 'index.html'))
});

app.listen(port);

console.log('Server running on port ' + port);

如果有人可以幫助我解決此問題以解決nodemon not found錯誤, nodemon not found

我通過將nodemon替換為node解決了這個問題。

正如@JDunken 指出的那樣, nodemon是一種開發工具。 它無法部署。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM