I have a few small react web apps I have made that I am trying to deploy to heroku. I found this https://github.com/mars/create-react-app-buildpack through a youTube video and supposedly this is/was a simple method for deployment. There are several steps the author lists (first two don't apply):
git init
heroku create $APP_NAME --buildpack
https://github.com/mars/create-react-app-buildpack.git
git add .
git commit -m "Start with create-react-app"
git push heroku master
heroku open
Once I get to the git push heroku master I get an error in console that says:
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'
I did some searching and found a few build scripts for my package.json file but none of them seem to work (""build": " webpack --config webpack.conf.js"")
Here is my 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"
}
}
Can anyone help me out here? I am logged into my heroku account already. Is there a simpler way than what I am doing here?
If you provide a git repo it may help to git to the issue quickly but for now make sure you installed
react-scripts
npm i react-scripts --save-dev
make sure -dev is there so it runs before server launch for more details
also, keep your client ( react app ) package.json including the same
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
also its very important to make sure you are using the right buildpacks
if its only react app no node.js for more details
heroku create $APP_NAME --buildpack mars/create-react-app
but if you are building dual with node.js
heroku buildpacks:clear
and consider to follow instructions here How to use create-react-app with a custom Node server on Heroku
You mentioned that "build": " webpack --config webpack.conf.js" is not working. I am guessing that is why you omitted it from your package.json. This is what is needed to resolve the error message. Once you get this script working in your package.json, then all should be good.
Looking at the start script, it's possible that you need to run webpack by specifying it from the .bin directory. I'm not sure what version of node you are using.
scripts: {
...
"build": "./node_modules/.bin/webpack --config webpack.conf.js",
...
}
Try this:
"build": "webpack"
This where I got it from.
https://webpack.js.org/guides/getting-started/
Related
I have two main folders for my project: server and client. Heroku only seems to care about the server/package.json. Deployment is going fine until it returns an error when the process runs the "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client" command from package.json.
Here's the error message from the console:
-----> Build
remote: Running heroku-postbuild
remote:
remote: > server#1.0.0 heroku-postbuild
remote: > npm install --prefix client && npm run build --prefix client
remote:
remote: npm ERR! code ENOENT
remote: npm ERR! syscall open
remote: npm ERR! path /tmp/build_25b1f86c/client/package.json
remote: npm ERR! errno -2
remote: npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_25b1f86c/client/package.json'
remote: npm ERR! enoent This is related to npm not being able to find a file.
remote: npm ERR! enoent
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.3i4hV/_logs/2022-08-05T15_34_56_961Z-debug-0.log
remote:
remote: -----> Build failed
Here's server/package.json:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"engines": {
"node": "16.16.0",
"npm": "8.11.0"
},
"scripts": {
"start": "node index.js",
"server": "nodemon index.js",
"client": "npm run start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.0",
"concurrently": "^7.3.0",
"cookie-session": "^2.0.0",
"express": "^4.18.1",
"mongoose": "^6.5.0",
"nodemon": "^2.0.19",
"passport": "^0.5.3",
"passport-google-oauth20": "^2.0.0",
"stripe": "^10.0.0"
}
}
Here's client/package.json:
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.3.0",
"#testing-library/user-event": "^13.5.0",
"axios": "^0.27.2",
"http-proxy-middleware": "^2.0.6",
"materialize-css": "^1.0.0-rc.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.0.2",
"react-router-dom": "^5.3.3",
"react-scripts": "5.0.1",
"react-stripe-checkout": "^2.6.3",
"redux": "^4.2.0",
"redux-thunk": "^2.4.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
I tried removing parts of "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client" to shorten it into "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false" in other deployments and it worked. It seems "npm install --prefix client && npm run build --prefix client" is the part not working in the heroku-postbuild script.
Would you have any idea how to fix this? Thanks!
OK, found it. My course TA helped me figure it out. The solution below worked.
In my Github repo called server, the client directory was completely missing, so, the Heroku server was likely having the same problem. And it did. I had to delete the .git directory in the client so version control doesn't think this is a submodule. From the root repository:
cd client
rm -r .git
git rm --cached .
cd ..
git add client
git commit -m "remove submodule"
git push origin main
git push heroku main
When trying to push to Heroku I keep getting this error:
remote: ! Push rejected to infinite-cove-33100.
remote:
To https://git.heroku.com/infinite-cove-33100.git
! [remote rejected] master -> master (pre-receive hook declined)
It always breaks at:
remote: > mern_ecommerce#1.0.0 heroku-postbuild /tmp/build_43ebd568
remote: > NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend
remote:
remote: up to date in 0.284s
remote: found 0 vulnerabilities
remote:
remote: npm ERR! code ENOENT
remote: npm ERR! syscall open
remote: npm ERR! path /tmp/build_43ebd568/frontend/package.json
remote: npm ERR! errno -2
remote: npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_43ebd568/frontend/package.json'
remote: npm ERR! enoent This is related to npm not being able to find a file.
All versions in the package.json are accurate, everything that's needed in .gitignore is there including node_modules, heroku has the right buildpack and everything has been added and committed with git.
I've been through: https://devcenter.heroku.com/articles/troubleshooting-node-deploys
and no solution yet.
This is the package.json where it keeps breaking:
{
"name": "mern_ecommerce",
"version": "1.0.0",
"engines": {"node": "14.15.1"},
"description": "MERN shopping cart app",
"main": "server.js",
"type": "module",
"scripts": {
"start": "node backend/server",
"server": "nodemon backend/server",
"client": "npm start --prefix frontend",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"data:import": "node backend/seeder",
"data:destroy": "node backend/seeder -d",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend"
},
"author": "John Doe",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"colors": "^1.4.0",
"dotenv": "^8.2.0",
"e
xpress": "^4.17.1",
"express-async-handler": "^1.1.4",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.11.4",
"morgan": "^1.10.0",
"multer": "^1.4.2",
"node": "^14.15.1",
"react": "^17.0.1",
"react-scripts": "^4.0.1"
},
"devDependencies": {
"concurrently": "^5.3.0",
"nodemon": "^2.0.6"
}
}
I don't know what the original problem was but I was able to deploy by using the deploy tab on the Heroku site via linking github... not how I wanted to do it but it works.
For anyone having trouble with their Heroku builds, it might be worthwhile to install npx by running npm install -g npx and let it inspect the contents of your package.json file by running npx #heroku/update-node-build-script.
Also see: https://www.npmjs.com/package/#heroku/update-node-build-script
For manual inspection check: https://help.heroku.com/P5IMU3MP/heroku-node-js-build-script-change-faq
try running npm install sometimes it's happening because you manually updated your package.json, which will not affect the package-lock.json hence it's different from the remote one hence can not get deployed
I've been trying to deploy a fresh Laravel with Vue in Heroku and this is the error that I got.
Skipping 'fsevents' build as platform linux is not supported
npm ERR! Cannot read property 'length' of undefined
...
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
Some possible problems:
- Node version not specified in package.json
https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
Love,
Heroku
Push rejected, failed to compile Node.js app.
Push failed
I have tried basic Heroku troubleshooting guide. Also, I manage to found this https://dev.to/saidichlil/comment/pn49 which doesn't seem to work base from the comment and still give it a shot and confirmed.
I am deploying from a github repo connected to heroku, by the way, and not by using Heroku CLI.
In your pacakge.json you'll want the engines declaration as #jake-price stated above and this post-build
"heroku-postbuild": "npm run production"
Also make sure your heroku/nodejs build pack is selected with the heroku/php buildpack
Your complete package.json may look something like this
{
"private": true,
"engines": {
"node": "12.x"
},
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --config=node_modules/laravel-mix/setup/webpack.config.js",
"heroku-postbuild": "npm run production"
},
"devDependencies": {
"#babel/preset-react": "^7.0.0",
"axios": "^0.19",
"bootstrap": "^4.0.0",
"cross-env": "^7.0",
"jquery": "^3.2",
"laravel-mix": "^5.0.1",
"lodash": "^4.17.19",
"popper.js": "^1.12",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"resolve-url-loader": "^3.1.0",
"sass": "^1.15.2",
"sass-loader": "^8.0.0"
}
}
Try and put what version of Node you want Heroku to use in your package.json
"engines": {
"node": "12.x"
}
If that doesn't work, you can also try and install it with the following command. This will skip the optional fsevents package (which isn't needed on Linux)
npm install --no-optional
Trying to deploy a Laravel+vue application to heroku but when using git push heroku master I get the following trace (only part of the whole trace is shown but it is the part which I believe to be the problem - if not let me know):
remote: npm ERR! code EINTEGRITY
remote: npm ERR! sha512-
Prh/h9CB1jBCBIjSLD6kvIWhMV5S25Bwv7yK0fYJSOTIyg1CmU9OqNdRVCkdWyQY1Hkvm+1YdXJzh3xYupq1KA==
integrity checksum failed when using sha512: wanted sha512-
Prh/h9CB1jBCBIjSLD6kvIWhMV5S25Bwv7yK0fYJSOTIyg1CmU9OqNdRVCkdWyQY1Hkvm+1YdXJzh3xYupq1KA== but
got sha512-
QItiGZBy5TstGy+q8mjQTMGRlDDOARXLxH+sgVm1n/LYeo0zFcQlcCh8m4zi8QxctrxB9Kue/lStc/RD5iLadQ==.
(896052 bytes)
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.8lpmC/_logs/2020-06-05T11_28_24_085Z-debug.log
remote:
remote: -----> Build failed
remote:
remote: We're sorry this build is failing! You can troubleshoot common issues here:
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote: Some possible problems:
remote:
remote: - Node version not specified in package.json
remote: https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-
version
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
and this my package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"postinstall": "npm run prod",
"heroku-postbuild": "npm run prod"
},
"devDependencies": {
"axios": "^0.19",
"bootstrap": "^4.0.0",
"cross-env": "^5.1",
"jquery": "^3.5.1",
"laravel-mix": "^5.0.1",
"lodash": "^4.17.13",
"popper.js": "^1.12",
"resolve-url-loader": "^2.3.1",
"sass": "^1.20.1",
"sass-loader": "^8.0.0",
"vue": "^2.5.17",
"vue-template-compiler": "^2.6.10"
},
"dependencies": {
"#fullcalendar/core": "^4.4.0",
"#fullcalendar/daygrid": "^4.4.0",
"#fullcalendar/interaction": "^4.4.0",
"#fullcalendar/vue": "^4.4.0",
"#types/dhtmlxgantt": "^6.0.2",
"admin-lte": "^3.0.2",
"babel-runtime": "^6.26.0",
"bootstrap-vue": "^2.15.0",
"dhtmlx-gantt": "^6.3.7",
"laravel-echo": "^1.7.0",
"laravel-vue-pagination": "^2.3.1",
"mdbvue": "^6.7.0",
"moment": "^2.24.0",
"pusher-js": "^5.1.1",
"sweetalert2": "^9.8.2",
"vform": "^1.0.1",
"vue-full-calendar": "^2.7.0",
"vue-print-nb": "^1.5.0",
"vue-progressbar": "^0.7.5",
"vue-router": "^3.1.6",
"vuex": "^3.1.3"
},
"engines": {
"node": "12.x"
}
}
There's a bunch of error inside and I have no idea why this happen. but after many research i try many ways bu i didn't find the solution .So any help guys i'm stuck here since 2 days
Where you have specified the node version also specify the node version.
see if it works. It worked for me.
"engines": { "node": "12.x", "npm": "your version" }
Specifying the engines object-block helped me with both a Laravel app and a Rails app
package.json (append)
"engines": {
"node": "12.x"
}
Sort-of odd, but when it works, it works.
I also added a #dependabot rebase so that my preview builds using heroku would allow me to verify in-branch that this was the only problem preventing the applications from building.
Check your versions of node and npm in terminal:
node -v
npm -v
and update both in your package.json (example):
"engines": {
"node": "14.x",
"npm": "7.x"
}
just putting node version didn't help me since heroku automatically tried to build another version of npm and crashed
read more here:
https://devcenter.heroku.com/articles/deploying-nodejs#specify-the-version-of-node
I am getting this error while I am trying to push my project to heroku. Backend is writtend in nodeJS, frontend in React. I think the problem is heroku-postbuild, because if I remove it, push works. I was searching for it but still I have no idea what is the reason. Can somebody help me?
/tmp/build_7504975f08f330415cdefb27437cfad9/node_modules/.bin/node: 1: /tmp/build_7504975f08f330415cdefb27437cfad9/node_modules/.bin/node: MZ����#: not found
/tmp/build_7504975f08f330415cdefb27437cfad9/node_modules/.bin/node: 1: /tmp/build_7504975f08f330415cdefb27437cfad9/node_modules/.bin/node: Syntax error: word unexpected (expecting ")")
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! project#1.0.0 heroku-postbuild: `cd client && npm install && npm run build`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the project#1.0.0 heroku-postbuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/npmcache.W89m8/_logs/2018-11-13T21_37_22_676Z-debug.log
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
Some possible problems:
- node_modules checked into source control
https://blog.heroku.com/node-habits-2016#9-only-git-the-important-bits
- Node version not specified in package.json
https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
Love,
Heroku
! Push rejected, failed to compile Node.js app.
! Push failed
package.json (server)
{
"name": "project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node server.js",
"server": "nodemon server.js",
"client-install": "npm install --prefix client",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "cd client && npm install && npm run build"
},
"author": "",
"license": "ISC",
"dependencies": {
"concurrently": "^4.0.1",
"express": "^4.16.4",
"jsonwebtoken": "^8.3.0",
"mongoose": "^5.3.4",
"node": "^8.10.0",
"nodemon": "^1.18.4",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"react-scripts": "1.0.11",
},
"devDependencies": {
"nodemon": "^1.18.4",
"react-scripts": "1.0.11"
}
}
package.json (client)
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"parallelshell": "^3.0.2",
"react-dom": "^16.5.2",
"react-redux": "^5.0.7",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-router-redux": "^4.0.8",
"react-scripts": "2.0.5",
"socket.io-client": "^1.7.3",
},
"scripts": {
"start": "parallelshell \"react-scripts start\" \"sass --watch src/styles/scss:src/styles/css --style compressed\"",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"sass": "sass --watch src/styles/scss:src/styles/css --style compressed",
"sass-nw": "sass src/styles/scss:src/styles/css"
},
"proxy": "http://localhost:5000/",
}
I ran into the similar error while troubleshooting a project. I resolved it by using the suggestions from the prompt.
Some possible problems:
- node_modules checked into source control
https://blog.heroku.com/node-habits-2016#9-only-git-the-important-bits
- Node version not specified in package.json
https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
So try do a "rm -rf node_modules" in the root directory if you checked node_modules into the repository. Heroku will install node_modules in the deployed environment and does not need your checked in version.