Create-React-App 部署到 Heroku 失败,并显示 `react-scripts: not found` [英] Create-React-App deployment to Heroku failed with ` react-scripts: not found`

查看:48
本文介绍了Create-React-App 部署到 Heroku 失败,并显示 `react-scripts: not found`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用 Create-React-App 开发 ReactJS 应用程序,该应用程序由我们的 Node/Express 服务器提供服务,该服务器也提供 API 服务.我们使用 node/JS buildpack 将整个服务器部署到 Heroku 并尝试从节点 package.jsonpostinstall 脚本中获取 CRA 构建步骤 npm run build/code> 文件,如@mars 本期所建议.

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.

问题是 Heroku 部署因此错误而失败.请注意,此错误有时在本地发生在我身上,但是来自 web_app 的 npm install 正在解决该问题,但在 Heroku 中运行时则不然.我有两个相关的问题:

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:

  1. 如何将同时提供 API 和 Create-React-App 应用程序的 Node/Express 应用程序部署到 Heroku?我可以提交我的构建目录,但这确实不是正确的方法.
  2. 为什么反应脚本消失了,我必须多次运行 npm install.

推荐答案

@johnnycon -

@johnnycon -

这正是问题所在,我在此Mars的答复://github.com/mars/create-react-app-buildpack/issues/32#issuecomment-276081892" rel="noreferrer">github 问题帖子:

This was exactly the issue and I've received the answer from Mars in this github issue post:

@philjoseph,react-scripts(默认情况下)是 CRA 应用程序的 devDependency,但 Heroku Node buildpack 的环境 NODE_ENV=production 导致 npm install 跳过 devDeps.

@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.

也安装这些 devDeps:

To install those devDeps too:

npm install --only=dev &&npm 安装 &&npm 运行构建

npm install --only=dev && npm install && npm run build

他还指出了这个优秀的 repo:https://github.com/mars/heroku-克拉节点

He also pointed to this excellent repo: https://github.com/mars/heroku-cra-node

我遵循了这个,它就像一个魅力:)

I followed this and it works like a charm :)

这篇关于Create-React-App 部署到 Heroku 失败,并显示 `react-scripts: not found`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆