node.js - Netlify 上的 React/Node 部署

标签 node.js reactjs heroku mern netlify

我最近向 heroku 部署了一个应用程序。但我想知道如何将同一个应用程序部署到 Netlify

我创建了一个在 Heroku 中运行良好的脚本:

"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix 
client && npm run build --prefix client".

我添加了与 Heroku 中相同的全局变量,并且也运行了相同的脚本,但出现了此错误:

2:34:44 PM: Error running command: Build script returned non-zero exit 
code: 127
2:34:44 PM: Failing build: Failed to build site
2:34:44 PM: failed during stage 'building site': Build script returned 
non-zero exit code: 127
2:34:44 PM: Finished processing build request in 25.404662076s

客户端包.json

    {
   "name": "client",
   "version": "0.1.0",
   "private": true,
   "dependencies": {
   "axios": "^0.18.0",
   "classnames": "^2.2.5",
   "jwt-decode": "^2.2.0",
   "moment": "^2.22.0",
   "react": "^16.3.1",
   "react-dom": "^16.3.1",
   "react-moment": "^0.7.0",
   "react-redux": "^5.0.7",
   "react-router-dom": "^4.2.2",
   "react-scripts": "1.1.4",
   "redux": "^3.7.2",
   "redux-thunk": "^2.2.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
      "proxy": "http://localhost:5000"
}

服务器包.json

{
  "name": "devconnector",
  "version": "1.0.0",
  "description": "Social network for developers",
  "main": "server.js",
  "scripts": {
      "client-install": "npm install --prefix client",
      "start": "node server.js",
      "server": "nodemon server.js",
      "client": "npm start --prefix client",
      "dev": "concurrently \"npm run server\" \"npm run client\"",
      "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install -- 
       prefix client && npm run build --prefix client"
  },
      "author": "Brad Traversy",
      "license": "MIT",
      "dependencies": {
           "bcryptjs": "^2.4.3",
           "body-parser": "^1.18.2",
           "concurrently": "^3.5.1",
           "express": "^4.16.3",
           "gravatar": "^1.6.0",
           "jsonwebtoken": "^8.2.0",
           "mongoose": "^5.0.12",
           "netlify-cli": "^1.2.3",
           "passport": "^0.4.0",
           "passport-jwt": "^4.0.0",
           "validator": "^9.4.1"
      },
      "devDependencies": {
           "nodemon": "^1.17.3"
      }
 }

最佳答案

在尝试部署后端时,Netlify 并不像 Heroku 那么直接。基本答案,你不能。

https://www.netlify.com/docs/functions/ 有一种方法可以使其工作,请参阅上面的链接,但我不知道该怎么做。

关于node.js - Netlify 上的 React/Node 部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51902639/

相关文章:

javascript - 创建 React Native 应用程序时出错 : Element type is invalid: expected a string or a class/function but got: object

c# - net::ERR_NAME_NOT_RESOLVED docker

node.js - 如何通过 aws-cli 创建具有嵌套属性定义的 dynamodb 模式?

node.js - 如何在不破坏 Node 导入的情况下连接 typescript 输出?

node.js - 在 mongoose 预查找中间件上添加条件

node.js - Sails.js - 使用多重连接获取对象(模型)

reactjs - 带有 React 类型的 TypeScript 将无法编译

ruby-on-rails - Heroku Rails 应用程序未加载页面

ruby-on-rails - Rails/Cappuccino应用程序未在Heroku上加载

heroku - godep : exec: "go": executable file not found in $PATH