在部署到Heroku之前,我应该在MERN应用程序的package.json文件的脚本中进行哪些更改?

如何解决在部署到Heroku之前,我应该在MERN应用程序的package.json文件的脚本中进行哪些更改?

我应该对MERN应用程序的根文件夹中的package.json文件的脚本进行哪些更改,该脚本还包含一个单独的frontend_client和backend_server子根文件夹?

现在,我在根文件夹中的package.json文件如下所示,我已将其提交到远程Heroku git并已成功编译,但是在启动应用程序时出现错误,如Heroku日志中所示

{
  "name": "root","version": "1.0.0","description": "","main": "index.js","scripts": {
    "test": "echo \"Error: no test specified\" && exit 1","dev": "concurrently \"cd backend_server && npm run dev\" \"cd frontend_client && npm start\"",},"repository": {
    "type": "git","url": "git+https://github.com/nishant-k-290195/p1.git"
  },"author": "Nishant Kumar","license": "ISC","engines": {
    "node": "12.18.3"
  },"bugs": {
    "url": "https://github.com/nishant-k-290195/p1/issues"
  },"homepage": "https://github.com/nishant-k-290195/p1#readme","devDependencies": {
    "concurrently": "^5.3.0"
  }
}

下面是heroku日志-

2020-09-05T17:33:43.489116+00:00 heroku[web.1]: Process exited with status 1
2020-09-05T17:33:43.528008+00:00 heroku[web.1]: State changed from starting to crashed
2020-09-05T17:34:31.525583+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=fast-anchorage-34297.herokuapp.com request_id=57a25f1b-6d5b-4549-8f7b-8cd87dce4267 fwd="183.83.146.132" dyno= connect= service= status=503 bytes= protocol=https
2020-09-05T17:34:32.283997+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=fast-anchorage-34297.herokuapp.com request_id=d8cd0ef2-d1db-4a8a-b3a1-0c4aca202e22 fwd="183.83.146.132" dyno= connect= service= status=503 bytes= protocol=https
2020-09-05T17:41:22.000000+00:00 app[api]: Build started by user nishant290195.nkr@gmail.com
2020-09-05T17:41:42.000000+00:00 app[api]: Build failed -- check your build output: https://dashboard.heroku.com/apps/a283d1cf-d0fe-41b3-b8da-73c343355213/activity/builds/2e47b96c-e89d-46d3-8eeb-a045848df017
2020-09-05T17:55:39.000000+00:00 app[api]: Build started by user nishant290195.nkr@gmail.com
2020-09-05T17:55:54.797062+00:00 app[api]: Deploy c0d16916 by user nishant290195.nkr@gmail.com
2020-09-05T17:55:54.797062+00:00 app[api]: Release v4 created by user nishant290195.nkr@gmail.com
2020-09-05T17:55:55.000000+00:00 app[api]: Build succeeded
2020-09-05T17:55:58.414761+00:00 heroku[web.1]: State changed from crashed to starting
2020-09-05T17:56:00.690083+00:00 heroku[web.1]: Starting process with command `npm run dev`
2020-09-05T17:56:03.649588+00:00 app[web.1]: 
2020-09-05T17:56:03.649613+00:00 app[web.1]: > root@1.0.0 dev /app
2020-09-05T17:56:03.649614+00:00 app[web.1]: > concurrently "cd backend_server && npm run dev" "cd frontend_client && npm start"
2020-09-05T17:56:03.649615+00:00 app[web.1]: 
2020-09-05T17:56:03.664007+00:00 app[web.1]: sh: 1: concurrently: not found
2020-09-05T17:56:03.669157+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-09-05T17:56:03.669442+00:00 app[web.1]: npm ERR! syscall spawn
2020-09-05T17:56:03.669852+00:00 app[web.1]: npm ERR! file sh
2020-09-05T17:56:03.670220+00:00 app[web.1]: npm ERR! errno ENOENT
2020-09-05T17:56:03.673293+00:00 app[web.1]: npm ERR! root@1.0.0 dev: `concurrently "cd backend_server && npm run dev" "cd frontend_client && npm start"`
2020-09-05T17:56:03.673429+00:00 app[web.1]: npm ERR! spawn ENOENT
2020-09-05T17:56:03.673587+00:00 app[web.1]: npm ERR!
2020-09-05T17:56:03.673750+00:00 app[web.1]: npm ERR! Failed at the root@1.0.0 dev script.
2020-09-05T17:56:03.673904+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-09-05T17:56:03.683841+00:00 app[web.1]: 
2020-09-05T17:56:03.684138+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-09-05T17:56:03.684329+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-09-05T17_56_03_675Z-debug.log
2020-09-05T17:56:03.737366+00:00 heroku[web.1]: Process exited with status 1
2020-09-05T17:56:03.780816+00:00 heroku[web.1]: State changed from starting to crashed
2020-09-05T17:56:03.783639+00:00 heroku[web.1]: State changed from crashed to starting
2020-09-05T17:56:05.855472+00:00 heroku[web.1]: Starting process with command `npm run dev`
2020-09-05T17:56:08.905828+00:00 app[web.1]: 
2020-09-05T17:56:08.905855+00:00 app[web.1]: > root@1.0.0 dev /app
2020-09-05T17:56:08.905855+00:00 app[web.1]: > concurrently "cd backend_server && npm run dev" "cd frontend_client && npm start"
2020-09-05T17:56:08.905856+00:00 app[web.1]: 
2020-09-05T17:56:08.925225+00:00 app[web.1]: sh: 1: concurrently: not found
2020-09-05T17:56:08.937713+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-09-05T17:56:08.938054+00:00 app[web.1]: npm ERR! syscall spawn
2020-09-05T17:56:08.938476+00:00 app[web.1]: npm ERR! file sh
2020-09-05T17:56:08.938852+00:00 app[web.1]: npm ERR! errno ENOENT
2020-09-05T17:56:08.943832+00:00 app[web.1]: npm ERR! root@1.0.0 dev: `concurrently "cd backend_server && npm run dev" "cd frontend_client && npm start"`
2020-09-05T17:56:08.943985+00:00 app[web.1]: npm ERR! spawn ENOENT
2020-09-05T17:56:08.944141+00:00 app[web.1]: npm ERR!
2020-09-05T17:56:08.944283+00:00 app[web.1]: npm ERR! Failed at the root@1.0.0 dev script.
2020-09-05T17:56:08.944404+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-09-05T17:56:08.954584+00:00 app[web.1]: 
2020-09-05T17:56:08.954809+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-09-05T17:56:08.954944+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-09-05T17_56_08_946Z-debug.log
2020-09-05T17:56:09.036221+00:00 heroku[web.1]: Process exited with status 1
2020-09-05T17:56:09.078574+00:00 heroku[web.1]: State changed from starting to crashed
2020-09-05T17:56:11.011048+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=fast-anchorage-34297.herokuapp.com request_id=35e7708e-0cc1-45cb-926f-623d4cde16b0 fwd="183.83.146.132" dyno= connect= service= status=503 bytes= protocol=https
2020-09-05T17:56:11.656448+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=fast-anchorage-34297.herokuapp.com request_id=8945408f-d80e-4d57-8ffc-f3bc1e33a8ad fwd="183.83.146.132" dyno= connect= service= status=503 bytes= protocol=https
2020-09-05T17:59:12.714272+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=fast-anchorage-34297.herokuapp.com request_id=c2d646c9-f779-488f-b272-29320f87a76d fwd="183.83.146.132" dyno= connect= service= status=503 bytes= protocol=https
2020-09-05T17:59:13.260112+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=fast-anchorage-34297.herokuapp.com request_id=445d6125-a6fc-4af6-975c-737091123a89 fwd="183.83.146.132" dyno= connect= service= status=503 bytes= protocol=https
2020-09-05T17:59:15.753473+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=fast-anchorage-34297.herokuapp.com request_id=4f4f07df-066e-4eef-b2af-c19b0654f212 fwd="183.83.146.132" dyno= connect= service= status=503 bytes= protocol=https
2020-09-05T17:59:16.257264+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=fast-anchorage-34297.herokuapp.com request_id=6f763484-4a76-40b1-a48f-a8b58b1ddc67 fwd="183.83.146.132" dyno= connect= service= status=503 bytes= protocol=https
2020-09-05T18:19:40.404117+00:00 heroku[web.1]: State changed from crashed to starting
2020-09-05T18:19:42.639891+00:00 heroku[web.1]: Starting process with command `npm run dev`
2020-09-05T18:19:45.146091+00:00 app[web.1]: 
2020-09-05T18:19:45.146144+00:00 app[web.1]: > root@1.0.0 dev /app
2020-09-05T18:19:45.146148+00:00 app[web.1]: > concurrently "cd backend_server && npm run dev" "cd frontend_client && npm start"
2020-09-05T18:19:45.146148+00:00 app[web.1]: 
2020-09-05T18:19:45.154837+00:00 app[web.1]: sh: 1: concurrently: not found
2020-09-05T18:19:45.159721+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-09-05T18:19:45.159910+00:00 app[web.1]: npm ERR! syscall spawn
2020-09-05T18:19:45.160045+00:00 app[web.1]: npm ERR! file sh
2020-09-05T18:19:45.160228+00:00 app[web.1]: npm ERR! errno ENOENT
2020-09-05T18:19:45.162886+00:00 app[web.1]: npm ERR! root@1.0.0 dev: `concurrently "cd backend_server && npm run dev" "cd frontend_client && npm start"`
2020-09-05T18:19:45.162963+00:00 app[web.1]: npm ERR! spawn ENOENT
2020-09-05T18:19:45.163063+00:00 app[web.1]: npm ERR!
2020-09-05T18:19:45.163163+00:00 app[web.1]: npm ERR! Failed at the root@1.0.0 dev script.
2020-09-05T18:19:45.163319+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-09-05T18:19:45.171480+00:00 app[web.1]: 
2020-09-05T18:19:45.171611+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-09-05T18:19:45.171645+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-09-05T18_19_45_164Z-debug.log
2020-09-05T18:19:45.226610+00:00 heroku[web.1]: Process exited with status 1
2020-09-05T18:19:45.261608+00:00 heroku[web.1]: State changed from starting to crashed
2020-09-05T19:10:59.294228+00:00 heroku[web.1]: State changed from crashed to starting
2020-09-05T19:11:01.544665+00:00 heroku[web.1]: Starting process with command `npm run dev`
2020-09-05T19:11:04.141984+00:00 app[web.1]: 
2020-09-05T19:11:04.142014+00:00 app[web.1]: > root@1.0.0 dev /app
2020-09-05T19:11:04.142015+00:00 app[web.1]: > concurrently "cd backend_server && npm run dev" "cd frontend_client && npm start"
2020-09-05T19:11:04.142015+00:00 app[web.1]: 
2020-09-05T19:11:04.149729+00:00 app[web.1]: sh: 1: concurrently: not found
2020-09-05T19:11:04.157981+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-09-05T19:11:04.158322+00:00 app[web.1]: npm ERR! syscall spawn
2020-09-05T19:11:04.158560+00:00 app[web.1]: npm ERR! file sh
2020-09-05T19:11:04.158822+00:00 app[web.1]: npm ERR! errno ENOENT
2020-09-05T19:11:04.163828+00:00 app[web.1]: npm ERR! root@1.0.0 dev: `concurrently "cd backend_server && npm run dev" "cd frontend_client && npm start"`
2020-09-05T19:11:04.163980+00:00 app[web.1]: npm ERR! spawn ENOENT
2020-09-05T19:11:04.164157+00:00 app[web.1]: npm ERR!
2020-09-05T19:11:04.164316+00:00 app[web.1]: npm ERR! Failed at the root@1.0.0 dev script.
2020-09-05T19:11:04.164471+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-09-05T19:11:04.183322+00:00 app[web.1]: 
2020-09-05T19:11:04.183591+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-09-05T19:11:04.183760+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-09-05T19_11_04_174Z-debug.log
2020-09-05T19:11:04.263772+00:00 heroku[web.1]: Process exited with status 1
2020-09-05T19:11:04.328653+00:00 heroku[web.1]: State changed from starting to crashed

解决方法

  • 后端的 package.json
  • 根据您的文件夹结构替换脚本中的文件位置
  • 此处 client 目录具有 react 代码,后端代码位于根目录本身中。
    "start": "NODE_ENV=production node server.js","client": "npm start --prefix client","heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
  • server.js
const path = require('path');

if (process.env.NODE_ENV === 'production') {
  // Set static folder
  app.use(express.static('client/build'));

  app.get('*',(req,res) => {
    res.sendFile(path.resolve(__dirname,'client','build','index.html'));
  });
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-