gpt4 book ai didi

node.js - npm 错误!缺少脚本 : build when deploying react app to heroku

转载 作者:太空宇宙 更新时间:2023-11-03 23:00:31 25 4
gpt4 key购买 nike

我制作了一些小型的 React Web 应用程序,我正在尝试将其部署到 Heroku。我找到了这个https://github.com/mars/create-react-app-buildpack通过 youTube 视频,据说这是一种简单的部署方法。作者列出了几个步骤(前两个不适用):

  1. git 初始化
  2. heroku 创建 $APP_NAME --buildpack https://github.com/mars/create-react-app-buildpack.git
  3. git 添加。
  4. git commit -m“从create-react-app开始”
  5. git push heroku master
  6. heroku 打开

一旦我到达 git Push heroku master,我就会在控制台中收到一个错误:

npm ERR! missing script: build
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /app/.npm/_logs/2018-03-26T16_55_19_748Z-debug.log
remote: ! Push rejected, failed to compile React.js (create-react-app) multi app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to my-simple-react-weather-app.
remote:
To https://git.heroku.com/my-simple-react-weather-app.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/my-simple-react-weather-app.git'

我做了一些搜索,找到了一些适合我的 package.json 文件的构建脚本,但它们似乎都不起作用 (""build": "webpack --config webpack.conf.js"")

这是我的 package.json:

{
"name": "redux-simple-starter",
"version": "1.0.0",
"description": "Simple React YouTube App",
"main": "index.js",
"scripts": {
"start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
"test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
"test:watch": "npm run test -- --watch"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.2.1",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.1.18",
"babel-preset-react": "^6.1.18",
"chai": "^3.5.0",
"chai-jquery": "^2.0.0",
"jquery": "^2.2.1",
"jsdom": "^8.1.0",
"mocha": "^2.4.5",
"react-addons-test-utils": "^0.14.7",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.0"
},
"dependencies": {
"babel-preset-stage-1": "^6.1.18",
"lodash": "^3.10.1",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-redux": "4.3.0",
"react-router": "^2.0.1",
"redux": "^3.0.4",
"youtube-api-search": "0.0.5"
}
}

有人可以帮我吗?我已经登录到我的 heroku 帐户。有没有比我在这里做的更简单的方法?

最佳答案

如果您提供 git 存储库,它可能有助于快速解决问题,但现在请确保您已安装

react 脚本

npm i react-scripts --save-dev

确保 -dev 存在,以便它在服务器启动之前运行 for more details

另外,请让您的客户端(react app)package.json 包含相同的内容

"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"

确保您使用正确的构建包也非常重要如果它唯一的 react 应用程序没有node.js for more details

heroku create $APP_NAME --buildpack mars/create-react-app

但是如果你使用 Node.js 构建 Dual

heroku buildpacks:clear

并考虑遵循此处的说明 How to use create-react-app with a custom Node server on Heroku

关于node.js - npm 错误!缺少脚本 : build when deploying react app to heroku,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49496872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com