如何解决在部署到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 举报,一经查实,本站将立刻删除。