对Heroku的Create-React-App部署失败,出现“react-scripts:not found” [英] Create-React-App deployment to Heroku failed with ` react-scripts: not found`
问题描述
我们正在使用Create-React-App开发ReactJS应用程序,该应用程序由我们也提供API的Node / Express服务器提供。我们使用node / JS buildpack将整个服务器部署到Heroku,并试图在 postinstall
npm run build >脚本从@mars package.json 文件问题/ 32rel =nofollow noreferrer>在本期中。
问题在于Heroku部署失败并出现此错误。请注意,这个错误在我的某个地方发生在本地,但然后来自web_app的 npm install
正在解决此问题,但在Heroku中运行时不会。我有两个相关的问题:
- 如何在Heroku中部署一个同时提供API和Create-React-App应用程序的Node / Express应用程序?我可以提交我的构建目录,但这真的不是正确的方式。
- 为什么react-scripts正在消失,我必须多次运行
npm install
。
@johnnycon -
这正是问题所在,我已在火星的 github发布帖子:
< blockquote>
@philjoseph,react-scripts是(默认情况下)CRA应用程序的devDependency,但是Heroku Node buildpack具有环境NODE_ENV = production,这会导致npm install跳过devDeps。
要安装这些devDeps:
npm install --only = dev&& npm install&& npm run build
他还指出了这个优秀的回购: https://github.com/mars/heroku-cra-node
我跟着这个,它像魅力一样工作:)
We're developing a ReactJS application using Create-React-App, that is served from our Node/Express server that also serves API's. We deploy the whole server to Heroku using node/JS buildpack and trying to get the CRA build step npm run build
in postinstall
script from the node package.json
file as suggested by @mars in this issue.
The issue is that Heroku deployment is failing with this error. Note that this error happen to me sometime locally but then a npm install
from the web_app is solving the issue, but not when run in Heroku. I have two related questions:
- How to deploy to Heroku a Node/Express app that serves both APIs and a Create-React-App application? I can commit my build directory but this is really not the right way.
- Why the react-scripts are disappearing and I have to run multiple times the
npm install
.
@johnnycon -
This was exactly the issue and I've received the answer from Mars in this github issue post:
@philjoseph, react-scripts is (by default) a devDependency for CRA apps, but Heroku Node buildpack has environment NODE_ENV=production which causes npm install to skip devDeps.
To install those devDeps too:
npm install --only=dev && npm install && npm run build
He also pointed to this excellent repo: https://github.com/mars/heroku-cra-node
I followed this and it works like a charm :)
这篇关于对Heroku的Create-React-App部署失败,出现“react-scripts:not found”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!