MERN无法部署到heroku

编程入门 行业动态 更新时间:2024-10-10 10:25:53

<a href=https://www.elefans.com/category/jswz/34/1771378.html style=MERN无法部署到heroku"/>

MERN无法部署到heroku

我正在尝试通过NodeJS渲染我的React应用并将其部署在Heroku上。但我似乎在浏览器中有此问题

未捕获的SyntaxError:意外的令牌'

该页面为空白白页。

我尝试了很多解决方案,但我似乎不知道出了什么问题,为什么主页不显示。

我的[[在NodeJS中

{ "name": "portfolio-app", "version": "1.0.0", "description": "a simple app", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build", "start": "node app.js", "client": "cd client && npm run start", "dev": "concurrently -n 'server,client' -c 'red,green' \"nodemon app.js\" \"npm run client\"" }, "dependencies": { "body-parser": "^1.19.0", "concurrently": "^5.2.0", "create-react-app": "^3.4.1", "express": "^4.17.1", "mongoose": "^5.9.6", "nodemon": "^2.0.2" }, "engines": { "node": "10.x" } }
我的[[

package.json

在React App中{ "name": "client", "version": "0.1.0", "private": true, "dependencies": { "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.5.0", "@testing-library/user-event": "^7.2.1", "history": "^4.10.1", "react": "^16.13.1", "react-dom": "^16.13.1", "react-scripts": "3.4.1" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, "eslintConfig": { "extends": "react-app" }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] }, "proxy": "http://localhost:8080" }

app.js

服务器文件:const express = require('express'), app = express(), bodyParser = require('body-parser'), nav = require('./routes/navigation'), path = require('path'), PORT = process.env.PORT || 8080; /* Settings */ app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: true})); app.use(express.static(__dirname + '/public')); /*Production settings*/ if(process.env.NODE_ENV === "production"){ app.use(express.static(path.join(__dirname, 'client/build'))); app.get('*', (req, res) => { res.sendFile(path.join(__dirname, 'client/build', 'index.html')); }); } /* Starting server */ app.listen(PORT, () => { console.log(`APP IS RUNNING ON PORT ${PORT}`); }); 回答如下:https://elements.heroku/buildpacks/mars/create-react-app-buildpack

问题已解决。

更多推荐

MERN无法部署到heroku

本文发布于:2024-05-07 08:30:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1755403.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:MERN   heroku

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!