【问题标题】:Issues with deploying MERN stack application部署 MERN 堆栈应用程序的问题
【发布时间】:2020-02-13 04:45:38
【问题描述】:

我无法部署我的全栈应用程序。

就文件夹结构而言,我的存储库看起来完全一样:

以下是我的 package.json:https://github.com/bradtraversy/mern_shopping_list

{
  "name": "clear",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start:prod": "NODE_ENV=production nodemon server.js",
    "debug": "ndb server.js",
    "server": "nodemon server.js",
    "client": "cd client && npm start",    
    "build": "cd client && npm run build",    
    "dev": "concurrently --kill-others-on-fail \"npm run server\" \"npm run client\"",
    "start": "node server.js",
    "heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build"    
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.19.0",
    "compression": "^1.7.4",
    "concurrently": "^5.1.0",
    "cookie-parser": "^1.4.4",
    "cors": "^2.8.5",
    "dotenv": "^8.1.0",
    "express": "^4.17.1",
    "express-mongo-sanitize": "^1.3.2",
    "express-rate-limit": "^5.0.0",
    "helmet": "^3.21.1",
    "hpp": "^0.2.2",
    "html-to-text": "^5.1.1",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^5.7.1",
    "morgan": "^1.9.1",
    "multer": "^1.4.2",
    "ndb": "^1.1.5",
    "nodemailer": "^6.3.0",
    "path": "^0.12.7",
    "pug": "^2.0.4",
    "slugify": "^1.3.5",
    "stripe": "^7.9.1",
    "validator": "^11.1.0",
    "xss-clean": "^0.1.1"
  },
  "engines": {
    "node": "^10"
  }
}

【问题讨论】:

  • 你在哪里部署?
  • heroku 或任何像 AWS 这样的云?
  • 我正在尝试在heroku上部署

标签: node.js reactjs heroku mern react-fullstack


【解决方案1】:

你能试试这个吗-

即server.js文件内容:-

const express = require("express");
const path = require("path");
const app = express();
require("dotenv").config();
app.use(express.static(path.join(__dirname, "build")));

app.get("/", function(req, res) {
  res.sendFile(path.join(__dirname, "build", "index.html"));
});

app.get("/*", function(req, res) {
  res.sendFile(path.join(__dirname, "build", "index.html"));
});

app.listen(process.env.PORT || 3000);

这是我的脚本部分:-

  "scripts": {
    "start:production": "npm install && npm run build && npm run start:prod",
    "start:prod": "cross-env NODE_ENV=production node server",
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

在生产中启动命令:-

npm run start:production

【讨论】:

  • 嘿 Ankit,我尝试了您推荐的代码,但收到以下消息。我也非常感谢你的帮助:):
  • 反应脚本:找不到命令 npm ERR!代码 ELIFECYCLE npm 错误!系统调用产生 npm 错误!文件 sh npm 错误! errno ENOENT npm 错误! clear@1.0.0 构建:react-scripts build npm 错误!产生 ENOENT npm 错误! n
  • 当我在本地部署时,我找到了以下 [OKAY] package.json 文件 - 尝试 'npm start' 7:46:15 PM web.1 | > clear@1.0.0 开始 /Users/test/app-name 7:46:15 PM web.1 | > 节点 server.js 7:46:22 PM web.1 |监听 5000 端口 7:46:24 PM web.1 |连接到 Mongodb 7:49:58 PM web.1 |获取 / 404 15.140 毫秒 - 139
猜你喜欢
  • 2021-09-14
  • 1970-01-01
  • 2020-08-19
  • 1970-01-01
  • 2021-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多