node.js - 我为电影开发了网站并成功将其推送到 Heroku(使用节点 js 和 React 完成)但它没有运行
问题描述
这是package.json
根react
应用程序
{
"name": "movie-timeline",
"version": "0.1.0",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.30",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"axios": "^0.19.2",
"bootstrap": "^4.5.2",
"create-react-app": "^3.4.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-icons": "^3.10.0",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.2",
"react-spring": "^8.0.27"
},
"scripts": {
"dev": "set PORT=3006 && react-scripts start",
"start": "serve -s build",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:3006",
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
...
],
"development": [
...
]
}
}
我添加了set PORT=3006 && react-scripts start"
脚本,以便它可以在本地和上运行Heroku
。
这是heroku
记录的内容:
$ heroku logs --tail
Warning: heroku update available from 7.38.2 to 7.42.6.
2020-08-12T22:32:51.450396+00:00 app[web.1]: npm ERR! errno ENOENT
2020-08-12T22:32:51.452680+00:00 app[web.1]: npm ERR! movie-timeline@0.1.0 start: `serve -s build`
2020-08-12T22:32:51.452896+00:00 app[web.1]: npm ERR! spawn ENOENT
2020-08-12T22:32:51.453058+00:00 app[web.1]: npm ERR!
2020-08-12T22:32:51.453205+00:00 app[web.1]: npm ERR! Failed at the movie-timeline@0.1.0 start script.
2020-08-12T22:32:51.453348+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-08-12T22:32:51.467442+00:00 app[web.1]:
2020-08-12T22:32:51.467627+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-08-12T22:32:51.467740+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-08-12T22_32_51_460Z-debug.log
2020-08-12T22:32:51.556136+00:00 heroku[web.1]: Process exited with status 1
2020-08-12T22:32:51.706650+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-13T00:12:06.031766+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-13T00:12:29.908831+00:00 heroku[web.1]: Starting process with command `npm start`
2020-08-13T00:12:34.256591+00:00 app[web.1]:
2020-08-13T00:12:34.256605+00:00 app[web.1]: > movie-timeline@0.1.0 start /app
2020-08-13T00:12:34.256606+00:00 app[web.1]: > serve -s build
2020-08-13T00:12:34.256606+00:00 app[web.1]:
2020-08-13T00:12:34.267835+00:00 app[web.1]: sh: 1: serve: not found
2020-08-13T00:12:34.277638+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-08-13T00:12:34.277976+00:00 app[web.1]: npm ERR! syscall spawn
2020-08-13T00:12:34.278160+00:00 app[web.1]: npm ERR! file sh
2020-08-13T00:12:34.278407+00:00 app[web.1]: npm ERR! errno ENOENT
// ...
有人能帮助我吗?
解决方案
当您推送到 时,它会从您的应用程序Heroku
中运行此脚本:package.json
react
{
"scripts": {
"start": "serve -s build",
// other
},
}
这从heroku
日志中得到证实......
// ...
2020-08-13T00:12:34.256605+00:00 app[web.1]: > movie-timeline@0.1.0 start /app
2020-08-13T00:12:34.256606+00:00 app[web.1]: > serve -s build
2020-08-13T00:12:34.256606+00:00 app[web.1]:
2020-08-13T00:12:34.267835+00:00 app[web.1]: sh: 1: serve: not found
// ...
因为您serve
在本地计算机上全局安装,所以项目运行。
因此,您需要在serve
本地安装heroku
以在启动应用程序时运行它。
$ npm install --save-dev serve
这样,heroku
将能够运行您的"start"
脚本。
推荐阅读
- python - 关于python的一个基本问题(函数外的差异变量和列表)
- vba - Excel VBA 中的 BLE 加密狗 API 接口
- php - PhpStorm 调试使脚本运行得比不启用调试更快?
- google-chrome - 从 chrome 扩展中的后台脚本调用 ajax 请求
- python - 使用python将文本文件转换为shapefile
- java - 具有基于类的实现的通用“集合”
- sass - React-Big-Calendar CSS 或 SASS 或两者兼而有之?
- c# - C# Selenium 表分页测试
- c# - 将 Azure Cosmos DB for Mongo-DB-API 连接字符串放在 Xamarin 应用程序中是否安全?
- javascript - How to recover the title of an