将Razzle React App部署到Heroku时出错

问题描述

我用create-react-app创建了一个小型网站。然后我意识到SEO的糟糕性,所以我决定迁移到Razzle,这应该是创建服务器端React应用程序的简单方法

我成功迁移了机器上的所有内容,但是当我尝试在Heroku上进行部署时,出现了一个错误(远程:sh:1:razzle:未找到)

我应该补充说我已经安装了快递服务器。

所以基本上树形结构是这样的:

MYAPP
-clientside
  -build
  -node_modules
  -public
    index.html
  -src
    app.js
    app.css
    ...
  package.json
-models
-node_modules
-public
-views
app.js
db.js
package.json

文件夹中的package.json看起来像这样:

{
  "name": "workspace","version": "1.0.0","description": "","main": "index.js","scripts": {
    "test": "echo \"Error: no test specified\" && exit 1","start": "node db.js","heroku-postbuild": "cd clientside && npm install && npm run build"
  },"author": "","license": "ISC","dependencies": {
    "amazon-product-api": "^0.4.4","body-parser": "^1.19.0","compression": "^1.7.4","dotenv": "^8.2.0","ejs": "^2.7.1","express": "^4.17.1","express-session": "^1.16.2","jquery": "^3.5.1","mongodb": "^3.6.2","mongoose": "^5.7.1","passport": "^0.4.0","passport-facebook": "^3.0.0","passport-local": "^1.0.0","passport-local-mongoose": "^5.0.1","prerender-node": "^3.2.5","react-router-dom": "^5.2.0"
  }
}

和客户端文件夹中的package.json:

{
  "name": "my-razzle-app","license": "MIT","scripts": {
    "start": "razzle start --type=spa","build": "razzle build --type=spa","test": "razzle test --env=jsdom","start:prod": "serve -s build/public"
  },"dependencies": {
    "@material-ui/core": "^4.11.0","bootstrap": "^4.5.3","express": "4.17.1","history": "^5.0.0","query-string": "^6.13.6","razzle-heroku": "^3.0.0","react": "16.14.0","react-bootstrap": "^1.4.0","react-dom": "16.14.0","react-ga": "^3.2.0","react-helmet": "^6.1.0","react-router-dom": "5.2.0"
  },"devDependencies": {
    "razzle": "3.3.7"
  }
}

app.js:

const express = require('express');
const path = require('path');
const app = express();
const db = require('./db');
const bodyParser = require('body-parser');
const { json } = require('body-parser');
const passport = require('passport');
const session = require('express-session');
const ObjectId = require('mongodb').ObjectID;
const fs = require('fs');

const expressSession = require('express-session')({
    secret: 'secret code name',resave: false,saveUninitialized: false
});
// Serve the static files from the React app
app.use(require('prerender-node'));
app.use(express.static(path.join(__dirname,'clientside/build')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(expressSession);

app.use(passport.initialize());
app.use(passport.session());

// some routes and API here



app.get("/edit",(req,res) => {

    res.send("edit page")
})



app.get('*',res) => {
    res.sendFile(path.join(__dirname + '/clientside/build/index.html'));
});

module.exports = app;

当我尝试部署该应用程序时出现错误

remote: sh: 1: razzle: not found
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! syscall spawn
remote: npm ERR! file sh
remote: npm ERR! errno ENOENT
remote: npm ERR! my-razzle-app@1.0.0 build: `razzle build --type=spa`
remote: npm ERR! spawn ENOENT
remote: npm ERR!
remote: npm ERR! Failed at the my-razzle-app@1.0.0 build script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.34SBb/_logs/2020-10-27T22_38_54_631Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! workspace@1.0.0 heroku-postbuild: `cd clientside && npm install && npm run build`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the workspace@1.0.0 heroku-postbuild script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.34SBb/_logs/2020-10-27T22_38_54_659Z-debug.log
remote: 

我真的不知道这是怎么回事。如果我没有在“ heroku-postbuild”中放置“ && npm run build”,则在尝试部署时没有错误,但是我的页面上没有“找不到”(我只能访问/ edit页面

有人可以告诉我我在做什么错吗?

非常感谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...