Error while deploying Angular App (NodeJS) to Heroku - node.js

I currently develop an angular5 app, and need to deploy it to Heroku.
This app is served using NodeJS.
After logging into Heroku, I create new app by:
heroku create angular-vbnmc
and it was successful, now i could open https://angular-vbnmc.herokuapp.com/ without problems, but still the content is blank, see picture below:
Then i deploy my app with following commands
git push heroku newFeatureBranch:master
Note: I didn't push my master branch but instead i push newFeatureBranch to remote heroku's master branch
and I got following error
Counting objects: 219, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (208/208), done.
Writing objects: 100% (219/219), 122.63 KiB | 3.50 MiB/s, done.
Total 219 (delta 111), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NODE_VERBOSE=false
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): 8.9.4
remote: engines.npm (package.json): 5.6.0
remote:
remote: Resolving node version 8.9.4...
remote: Downloading and installing node 8.9.4...
remote: npm 5.6.0 already installed with node
remote:
remote: -----> Restoring cache
remote: Skipping cache restore (not-found)
remote:
remote: -----> Building dependencies
remote: Prebuild detected (node_modules already exists)
remote: Rebuilding any native modules
remote: bootstrap#4.0.0 /tmp/build_61c2abaea4d9525f4aeb3f08e81769a2/node_modules/bootstrap
remote: Installing any new modules (package.json)
remote:
remote: > uws#0.14.5 install /tmp/build_61c2abaea4d9525f4aeb3f08e81769a2/node_modules/uws
remote: > node-gyp rebuild > build_log.txt 2>&1 || exit 0
remote:
remote:
remote: > node-sass#4.7.2 install /tmp/build_61c2abaea4d9525f4aeb3f08e81769a2/node_modules/node-sass
remote: > node scripts/install.js
remote:
remote: Downloading binary from https://github.com/sass/node-sass/releases/download/v4.7.2/linux-x64-57_binding.node
remote: Download complete
remote: Binary saved to /tmp/build_61c2abaea4d9525f4aeb3f08e81769a2/node_modules/node-sass/vendor/linux-x64-57/binding.node
remote: Caching binary to /tmp/npmcache.ShxWb/node-sass/4.7.2/linux-x64-57_binding.node
remote:
remote: > uglifyjs-webpack-plugin#0.4.6 postinstall /tmp/build_61c2abaea4d9525f4aeb3f08e81769a2/node_modules/webpack/node_modules/uglifyjs-webpack-plugin
remote: > node lib/post_install.js
remote:
remote:
remote: > node-sass#4.7.2 postinstall /tmp/build_61c2abaea4d9525f4aeb3f08e81769a2/node_modules/node-sass
remote: > node scripts/build.js
remote:
remote: Binary found at /tmp/build_61c2abaea4d9525f4aeb3f08e81769a2/node_modules/node-sass/vendor/linux-x64-57/binding.node
remote: Testing binary
remote: Binary is fine
remote:
remote: > angular-vbnmc#0.0.0 postinstall /tmp/build_61c2abaea4d9525f4aeb3f08e81769a2
remote: > ng build --prod
remote:
remote:
remote: An error occured during the build:
remote: Error: ENOENT: no such file or directory, open '/tmp/build_61c2abaea4d9525f4aeb3f08e81769a2/node_modules/bootstrap/dist/js/bootstrap.min.js'
remote: ENOENT: no such file or directory, open '/tmp/build_61c2abaea4d9525f4aeb3f08e81769a2/node_modules/bootstrap/dist/js/bootstrap.min.js'
remote: Error: ENOENT: no such file or directory, open '/tmp/build_61c2abaea4d9525f4aeb3f08e81769a2/node_modules/bootstrap/dist/js/bootstrap.min.js'
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! angular-vbnmc#0.0.0 postinstall: `ng build --prod`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the angular-vbnmc#0.0.0 postinstall script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.ShxWb/_logs/2018-03-06T04_54_08_334Z-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_modules checked into source control
remote: https://blog.heroku.com/node-habits-2016#9-only-git-the-important-bits
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to angular-vbnmc.
remote:
To https://git.heroku.com/angular-vbnmc.git
! [remote rejected] 12-Deployment -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/angular-vbnmc.git'
For additional information, here is my package.json:
{
"name": "angular-vbnmc",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "node server.js",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ng build --prod"
},
"private": true,
"dependencies": {
"#angular/animations": "^5.2.7",
"#angular/cli": "1.6.6",
"#angular/common": "^5.2.7",
"#angular/compiler": "^5.2.7",
"#angular/compiler-cli": "^5.2.7",
"#angular/core": "^5.2.7",
"#angular/forms": "^5.2.7",
"#angular/http": "^5.2.7",
"#angular/platform-browser": "^5.2.7",
"#angular/platform-browser-dynamic": "^5.2.7",
"#angular/router": "^5.2.7",
"bootstrap": "^4.0.0",
"core-js": "^2.4.1",
"express": "^4.16.2",
"jquery": "^3.3.1",
"popper.js": "^1.13.0",
"rxjs": "^5.5.6",
"typescript": "^2.6.2",
"zone.js": "^0.8.19"
},
"devDependencies": {
"#angular/language-service": "^5.2.7",
"#types/jasmine": "~2.8.3",
"#types/jasminewd2": "~2.0.2",
"#types/node": "^6.0.101",
"codelyzer": "^4.2.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "5.8.0"
},
"engines": {
"node": "8.9.4",
"npm": "5.6.0"
}
}
Why is this happening? and how to fix this error?

Related

Nodejs: failed to push some refs to 'https://git.heroku.com/myproject.git'

I made a portfolio with Reactjs and a little bit of nodejs to implement nodemailer, and now I'm trying to deploy to heroku but I'm getting this error: ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/dedaportfolio.git
I'm trying everthing but it seems nothing working, I did a lot of research around but nothing worked to me
Here is the error when I'm trying to push to heroku
Enumerating objects: 38099, done.
Counting objects: 100% (38099/38099), done.
Delta compression using up to 8 threads
Compressing objects: 100% (28232/28232), done.
Writing objects: 100% (38099/38099), 98.10 MiB | 108.00 KiB/s, done.
Total 38099 (delta 8542), reused 38081 (delta 8535), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NODE_VERBOSE=false
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): 16.15.0
remote: engines.npm (package.json): 7.24.2
remote:
remote: Resolving node version 16.15.0...
remote: Downloading and installing node 16.15.0...
remote: Bootstrapping npm 7.24.2 (replacing 8.5.5)...
remote: npm 7.24.2 installed
remote:
remote: -----> Installing dependencies
remote: Installing node modules (package.json)
remote:
remote: added 89 packages, and audited 90 packages in 8s
remote:
remote: 12 packages are looking for funding
remote: run `npm fund` for details
remote:
remote: 1 critical severity vulnerability
remote:
remote: To address all issues (including breaking changes), run:
remote: npm audit fix --force
remote:
remote: Run `npm audit` for details.
remote:
remote: -----> Build
remote: Detected both "build" and "heroku-postbuild" scripts
remote: Running heroku-postbuild
remote:
remote: > myportfolio#1.0.0 heroku-postbuild
remote: > cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build
remote:
remote:
remote: up to date, audited 1466 packages in 3s
remote:
remote: 194 packages are looking for funding
remote: run `npm fund` for details
remote:
remote: 7 high severity vulnerabilities
remote:
remote: To address issues that do not require attention, run:
remote: npm audit fix
remote:
remote: To address all issues (including breaking changes), run:
remote: npm audit fix --force
remote:
remote: Run `npm audit` for details.
remote:
remote: added 64 packages, removed 188 packages, changed 281 packages, and audited 1342 packages in 27s
remote:
remote: 207 packages are looking for funding
remote: run `npm fund` for details
remote:
remote: 6 high severity vulnerabilities
remote:
remote: To address all issues (including breaking changes), run:
remote: npm audit fix --force
remote:
remote: Run `npm audit` for details.
remote:
remote: > frontend#0.1.0 build
remote: > react-scripts build
remote:
remote: sh: 1: react-scripts: Permission denied
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: If you're stuck, please submit a ticket so we can help:
remote: https://help.heroku.com/
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to dedaportfolio.
remote:
To https://git.heroku.com/dedaportfolio.git
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/dedaportfolio.git'
this the package.json in the root of my project
{
"name": "myportfolio",
"version": "1.0.0",
"engines": {
"node": "16.15.0",
"npm":"7.24.2"
},
"description": "",
"main": "index.js",
"scripts": {
"client": "cd client && npm start",
"server": "nodemon server.js",
"build": "cd client && npm run build",
"dev":"concurrently --kill-others-on-fail \"npm run server\" \"npm run client\"",
"start": "node server.js",
"heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"nodemailer": "^4.7.0"
},
"devDependencies": {
"concurrently": "^7.3.0"
}
}
This is my client package.json
{
"name": "client",
"version": "0.1.0",
"engines": {
"node": "16.15.0"
},
"private": true,
"dependencies": {
"#fortawesome/free-brands-svg-icons": "^6.1.2",
"#fortawesome/free-solid-svg-icons": "^6.1.2",
"#fortawesome/react-fontawesome": "^0.2.0",
"#testing-library/react": "^13.3.0",
"#testing-library/user-event": "^13.5.0",
"axios": "^0.27.2",
"bootstrap": "^5.2.0",
"framer-motion": "^7.0.0",
"react": "^18.2.0",
"react-bootstrap": "^2.4.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.3.0",
"react-scripts": "^5.0.1",
"react-scroll": "^1.8.7",
"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"
]
}
}
The final three messages here:
To https://git.heroku.com/dedaportfolio.git
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/dedaportfolio.git'
are from Git itself and are simply a summary of the fact that Heroku (not Git) didn't like your code. Ignore them entirely as they add no information whatsoever; pay attention only to the remote:-prefixed lines. Git relays these lines to you whenever Heroku tells you why it does not like your code.
The remaining problems are all specific to either Heroku or your code. In this case, the errors come from npm, which is noting:
high severity vulnerabilities
which you should fix because security vulnerabilities are bad, but most importantly, from the next step in the build process:
sh: 1: react-scripts: Permission denied
which simply means that your react-scripts in the stuff you're deploying is wrong, so have a look at that.

Heroku Next JS app push rejected because of Node version

When trying to push my app to Heroku I am getting the following errors (edited for brevity):
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NODE_VERBOSE=false
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): >=v12.22.5
remote: engines.npm (package.json): >=6.14.14
remote:
remote: Resolving node version >=v12.22.5...
remote: Could not parse Version Requirements '>=v12.22.5': the given version requirement is invalid
remote: Downloading and installing node 17.0.1...
remote: Bootstrapping npm >=6.14.14 (replacing 8.1.0)...
remote: npm >=6.14.14 installed
My package.json (name redacted):
{
"name": "########",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start -p $PORT"
},
"engines": {
"node": "16.13.0"
},
"dependencies": {
"#stripe/react-stripe-js": "^1.4.1",
"#stripe/stripe-js": "^1.15.0",
"#zeit/next-css": "^1.0.0",
"axios": "^0.21.4",
"base-64": "^1.0.0",
"bootstrap": "^4.6.0",
"cookie": "^0.4.1",
"date-and-time": "^1.0.0",
"js-cookie": "^2.2.1",
"next": "^11.1.2",
"react": "17.0.2",
"react-bootstrap": "^1.5.2",
"react-calendar": "^3.3.1",
"react-datepicker": "^4.2.1",
"react-dom": "17.0.2",
"react-hook-form": "^7.17.4",
"react-icons": "^4.2.0",
"react-image-gallery": "^1.0.9",
"stripe": "^8.154.0"
}
}
... and further down the error trail:
remote: Error: error:0308010C:digital envelope routines::unsupported
remote: at new Hash (node:internal/crypto/hash:67:19)
remote: at Object.createHash (node:crypto:130:10)
remote: at BulkUpdateDecorator.hashFactory (/tmp/build_f62151d1/node_modules/next/dist/compiled/webpack/bundle5.js:138971:18)
remote: at BulkUpdateDecorator.update (/tmp/build_f62151d1/node_modules/next/dist/compiled/webpack/bundle5.js:138872:50)
remote: at /tmp/build_f62151d1/node_modules/next/dist/compiled/webpack/bundle5.js:59321:9
remote: at processTicksAndRejections (node:internal/process/task_queues:83:21)
remote: at runNextTicks (node:internal/process/task_queues:65:3)
remote: at processImmediate (node:internal/timers:437:9) {
remote: opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
remote: library: 'digital envelope routines',
remote: reason: 'unsupported',
remote: code: 'ERR_OSSL_EVP_UNSUPPORTED'
remote: }
remote: Node.js v17.0.1
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: - Dangerous semver range (>) in engines.node
And, at the end of the error messages, I'm not sure if this is a separate error. I changed my master branch to main a while back and I'm not sure if this is also telling me that I may have done this incorrectly (seems fine on GitHub):
remote: Verifying deploy...
remote:
remote: ! Push rejected to #########.
remote:
To https://git.heroku.com/########.git
! [remote rejected] main -> main (pre-receive hook declined)
I have been 'around the houses' on Google trying various and many fixes with no answer that worked. It looks to me as if Heroku is reading the wrong information from my package.json? Many thanks for any replies.
Got some help from Heroku support for this. My problem seemed to match a current use case that's currently out there online but I don't think this is the same. In case anyone else has the same issue I'll put my solutions here.
Heroku build was trying to automatically install version 17 of Node because it didn't understand the 'engines' version I had in my package.json at that time, and Heroku build is not compatible with version 17.x
The version of package.json 'stuck' in Heroku's build
"engines": {
"node": ">=v12.22.5"
},
But I changed that version multiple times during tesing and it seems Heroku didn't notice the changes to package.json. Heroku support told me to run a cache clearance and that worked. Once I ran the cache clearance Heroku build then picked up the correct version of Node from the 'engines' element. Here's how to clear the build cache
Install heroku-builds from the Heroku CLI
heroku plugins:install heroku-builds
Ensure the correct version of Node is on your local machine, but more importantly make sure the correct version is referenced in package.json. I decided on version 16.13.0
"engines": {
"node": "16.13.0"
},
Run the Heroku cache clearance
heroku builds:cache:purge -a example-app
Then redeploy your app. In my case the issue was fixed. Not sure if Heroku agree (and I'm not qualified to argue) but I feel the error in the end was because the cache needed to be cleared.
References:
Clear the build cache:
https://help.heroku.com/18PI5RSY/how-do-i-clear-the-build-cache
Supported Node versions:
https://devcenter.heroku.com/articles/nodejs-support#supported-runtimes

Heroku Deployment SassError: File to import not found or unreadable. Works fine locally

Attempting to deploy to heroku for the first time, and i've been getting this sasserror which causes the build to fail and reject.
Steps taken for resolution
Delete node sass and node modules / reinstall / push to master repo
Adjust import path to #import './scss/_variables.scss';
Delete the first import to check if that file was the issue
Update node to support node-sass compatibility
Question
Create React App has webpack built internally, do i need to add my own webpack config for sass-loaders, css-loaders, style-loaders?
i've only ever used webpack with rails before, if i do need webpack, for my output params, what should replace the "bundle.js" i get from rails?
Terminal response
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/nodejs
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NODE_VERBOSE=false
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): 10.x
remote: engines.npm (package.json): unspecified (use default)
remote:
remote: Resolving node version 10.x...
remote: Downloading and installing node 10.24.1...
remote: Using default npm version: 6.14.12
remote:
remote: -----> Installing dependencies
remote: Installing node modules
remote:
remote: > nodemon#2.0.4 postinstall /tmp/build_f7e8f26d/node_modules/nodemon
remote: > node bin/postinstall || exit 0
remote:
remote: Love nodemon? You can now support the project via the open collective:
remote: > https://opencollective.com/nodemon/donate
remote:
remote: added 358 packages in 10.306s
remote:
remote: -----> Build
remote: Running heroku-postbuild
remote:
remote: > server#1.0.0 heroku-postbuild /tmp/build_f7e8f26d
remote: > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
remote:
remote:
remote: > node-sass#6.0.0 install /tmp/build_f7e8f26d/client/node_modules/node-sass
remote: > node scripts/install.js
remote:
remote: Downloading binary from https://github.com/sass/node-sass/releases/download/v6.0.0/linux-x64-64_binding.node
remote: Download complete
remote: Binary saved to /tmp/build_f7e8f26d/client/node_modules/node-sass/vendor/linux-x64-64/binding.node
remote: Caching binary to /tmp/npmcache.gWg6N/node-sass/6.0.0/linux-x64-64_binding.node
remote:
remote: > core-js#2.6.12 postinstall /tmp/build_f7e8f26d/client/node_modules/babel-runtime/node_modules/core-js
remote: > node -e "try{require('./postinstall')}catch(e){}"
remote:
remote:
remote: > core-js#3.12.1 postinstall /tmp/build_f7e8f26d/client/node_modules/core-js
remote: > node -e "try{require('./postinstall')}catch(e){}"
remote:
remote:
remote: > core-js-pure#3.12.1 postinstall /tmp/build_f7e8f26d/client/node_modules/core-js-pure
remote: > node -e "try{require('./postinstall')}catch(e){}"
remote:
remote:
remote: > ejs#2.7.4 postinstall /tmp/build_f7e8f26d/client/node_modules/ejs
remote: > node ./postinstall.js
remote:
remote:
remote: > node-sass#6.0.0 postinstall /tmp/build_f7e8f26d/client/node_modules/node-sass
remote: > node scripts/build.js
remote:
remote: Binary found at /tmp/build_f7e8f26d/client/node_modules/node-sass/vendor/linux-x64-64/binding.node
remote: Testing binary
remote: Binary is fine
remote: added 2124 packages from 812 contributors and audited 2131 packages in 43.95s
remote:
remote: 139 packages are looking for funding
remote: run `npm fund` for details
remote:
remote: found 81 vulnerabilities (80 moderate, 1 high)
remote: run `npm audit fix` to fix them, or `npm audit` for details
remote:
remote: > client#0.1.0 build /tmp/build_f7e8f26d/client
remote: > react-scripts build
remote:
remote: Creating an optimized production build...
remote: Failed to compile.
remote:
remote: ./src/App.scss
remote: SassError: File to import not found or unreadable: ./scss/_variables.scss.
remote: on line 2 of src/App.scss
remote: >> #import './scss/_variables.scss';
remote:
remote: ^
remote:
remote:
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! client#0.1.0 build: `react-scripts build`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the client#0.1.0 build script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.gWg6N/_logs/2021-05-25T08_12_53_624Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! server#1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the server#1.0.0 heroku-postbuild script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.gWg6N/_logs/2021-05-25T08_12_53_642Z-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: If you're stuck, please submit a ticket so we can help:
remote: https://help.heroku.com/
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
App.scss
// Abstracts
#import 'scss/variables';
#import 'scss/mixins';
// Base
#import 'scss/globals';
// Components
#import 'scss/header';
#import 'scss/showcase';
#import 'scss/hero';
#import 'scss/feature';
#import 'scss/postLanding';
#import 'scss/footer';
#import 'scss/auth';
#import 'scss/postList';
...etc
client package json
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.21.1",
"cra-template": "1.0.3",
"moment": "^2.29.1",
"node-sass": "^6.0.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-helmet": "^6.1.0",
"react-moment": "^1.0.0",
"react-redux": "^7.2.1",
"react-router-dom": "^5.2.0",
"react-scripts": "^4.0.3",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
"redux-thunk": "^2.3.0",
"uuid": "^8.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"proxy": "http://127.0.0.1:5000",
"secure": false,
"devDependencies": {}
}
server package json
{
"name": "server",
"version": "1.0.0",
"description": "jounii",
"main": "server.js",
"scripts": {
"start": "node server.js",
"server": "nodemon server.js",
"client": "npm 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": "Andrew Huang",
"license": "MIT",
"dependencies": {
"aws-sdk": "^2.771.0",
"axios": "^0.21.1",
"bcryptjs": "^2.4.3",
"colors": "^1.4.0",
"concurrently": "^5.3.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-async-handler": "^1.1.4",
"faker": "^5.1.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
"mongoose": "^5.12.3",
"morgan": "^1.10.0",
"multer": "^1.4.2",
"multer-s3": "^2.9.0",
"node-geocoder": "^3.27.0",
"nodemailer": "^6.6.0",
"request": "^2.88.2"
},
"devDependencies": {
"nodemon": "^2.0.4"
},
"engines": {
"node": "10.x"
}
}
File tree
enter image description here
Try this:
https://create-react-app.dev/docs/adding-a-sass-stylesheet
f you set SASS_PATH=node_modules:src, this will allow you to do imports like
#import 'styles/colors'; // assuming a styles directory under src/, where _colors.scss partial file exists.
#import 'nprogress/nprogress'; // importing a css file from the nprogress node module

Can't deploy React app to Heroku due to webpack

I'm trying to deploy a react app (not Create-react-app), which consist of my own webpack configurations. I can Build the app successfully locally and running locally successfully. But when I push to Heroku, git push heroku master I get the following message:
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NPM_CONFIG_PRODUCTION=true
remote: YARN_PRODUCTION=true
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=false
remote: NODE_VERBOSE=false
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): 10.x
remote: engines.npm (package.json): unspecified (use default)
remote: engines.yarn (package.json): 1.x
remote:
remote: Resolving node version 10.x...
remote: Downloading and installing node 10.16.0...
remote: Using default npm version: 6.9.0
remote: Resolving yarn version 1.x...
remote: Downloading and installing yarn (1.16.0)...
remote: Installed yarn 1.16.0
remote:
remote: -----> Restoring cache
remote: Caching has been disabled because NODE_MODULES_CACHE=false
remote:
remote: -----> Installing dependencies
remote: Installing node modules (yarn.lock)
remote: yarn install v1.16.0
remote: [1/4] Resolving packages...
remote: [2/4] Fetching packages...
remote: info fsevents#1.2.9: The platform "linux" is incompatible with this module.
remote: info "fsevents#1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
remote: [3/4] Linking dependencies...
remote: [4/4] Building fresh packages...
remote: Done in 18.83s.
remote:
remote: -----> Build
remote: Running build (yarn)
remote: yarn run v1.16.0
remote: $ rm -rf build/ && webpack --env.mode production
remote:
remote: Insufficient number of arguments or no entry found.
remote: Alternatively, run 'webpack(-cli) --help' for usage info.
remote:
remote: Hash: 9809f658cd5ff48864d7
remote: Version: webpack 4.33.0
remote: Time: 555ms
remote: Built at: 06/12/2019 9:16:13 PM
remote:
remote: ERROR in Entry module not found: Error: Can't resolve 'babel-loader' in '/tmp/build_429e145805178d81754292048e646eab'
remote: Child html-webpack-plugin for "index.html":
remote: 1 asset
remote: Entrypoint undefined = index.html
remote: [0] ./node_modules/html-webpack-plugin/lib/loader.js!./public/index.html 1.9 KiB {0} [built]
remote: [2] (webpack)/buildin/global.js 472 bytes {0} [built]
remote: [3] (webpack)/buildin/module.js 497 bytes {0} [built]
remote: + 1 hidden module
remote: error Command failed with exit code 2.
remote: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
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: If you're stuck, please submit a ticket so we can help:
remote: https://help.heroku.com/
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to react-go-fullstack.
remote:
This is my package.json:
{
"name": "fullstack-course",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "rm -rf build/ && webpack-dev-server --env.mode development --hot",
"build": "rm -rf build/ && webpack --env.mode production"
},
"engines": {
"node": "10.x",
"yarn": "1.x"
},
"repository": {
"type": "git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/NaseebullahSafi/fullstack-course/issues"
},
"devDependencies": {
"#babel/cli": "^7.2.3",
"#babel/core": "^7.4.0",
"#babel/preset-env": "^7.4.2",
"#babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.6",
"babel-plugin-styled-components": "^1.10.0",
"clean-webpack-plugin": "^2.0.1",
"css-loader": "^2.1.1",
"style-loader": "^0.23.1"
},
"dependencies": {
"copy-webpack-plugin": "^5.0.3",
"html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "^0.7.0",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"prop-types": "^15.7.2",
"react": "^16.8.5",
"react-dom": "^16.8.6",
"react-hot-loader": "^4.8.0",
"react-redux": "^6.0.1",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0",
"resources-manifest-webpack-plugin": "^3.0.0",
"styled-components": "^4.2.0",
"webpack": "^4.29.6",
"webpack-cli": "^3.3.4",
"webpack-dev-server": "^3.2.1",
"webpack-merge": "^4.2.1"
}
}
Can someone please explain what the issue is, and how can one resolve it.
Thanks

Deploy Angular Universal to heroku, failed to compile Node.js app

I've been trying to deploy an Angular Universal app to heroku
No matter what I do the same error is returned
"failed to compile Node.js app."
I've set up a procfile, I've specified "engines"
(I've tried at the start and the end of the script),
I've moved some packages form devDependencies to dependencies in package.json (At one point putting all packages in to dependencies)
I've tried, committing my node folder.
I even used a completely different package.json And it still gives me exactly the same response!!?
Which tells me; I think, that it has nothing to do with dependancies, I'm using for this project?
using:
git add .
git commit -m"message"
git push heroku master
The response:
Compressing objects: 100% (252/252), done.
Writing objects: 100% (256/256), 3.20 MiB | 319.00 KiB/s, done.
Total 256 (delta 116), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NODE_VERBOSE=false
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): unspecified
remote: engines.npm (package.json): unspecified (use default)
remote:
remote: Resolving node version 8.x...
remote: Downloading and installing node 8.11.2...
remote: Using default npm version: 5.6.0
remote:
remote: -----> Restoring cache
remote: Skipping cache restore (not-found)
remote:
remote: -----> Building dependencies
remote: Installing node modules (package.json + package-lock)
remote: npm ERR! Unexpected token < in JSON at position 108
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.j8wgx/_logs/2018-05-21T14_34_17_856Z-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:
remote: ! Push rejected to ma-leon.
remote:
To https://git.heroku.com/ma-leon.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/ma-leon.git'
My package.json:
{
"name": "maleon",
"version": "1.0.0",
"license": "MIT",
"main": "index.js",
"scripts": {
"ng": "ng",
"start": "node index.js",
"build:es2015": "node node_modules/babel-cli/bin/babel.js node_modules/ngx-page-scroll/ --out-dir node_modules/ngx-page-scroll/ --presets es2015",
"postinstall": "npm run build:es2015 && ng build --prod && ng build --prod --app 1 --output-hashing none",
"fix-scroll": "node node_modules/babel-cli/bin/babel.js node_modules/ngx-page-scroll/ --out-dir node_modules/ngx-page-scroll/ --presets es2015",
"lint": "tslint \"src/**/*.ts\" --project src/tsconfig.json --type-check && tslint \"e2e/**/*.ts\" --project e2e/tsconfig.json --type-check",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"#angular/animations": "^5.2.0",
"#angular/common": "^5.2.10",
"#angular/compiler": "^5.2.0",
"#angular/core": "^5.2.10",
"#angular/forms": "^5.2.10",
"#angular/http": "^5.2.0",
"#angular/platform-browser": "^5.2.0",
"#angular/platform-browser-dynamic": "^5.2.0",
"#angular/platform-server": "^5.2.10",
"#angular/router": "^5.2.0",
"#nguniversal/express-engine": "^5.0.0",
"#nguniversal/module-map-ngfactory-loader": "^5.0.0",
"babel-cli": "^6.26.0",
"body-parser": "^1.17.1",
"bootstrap": "^3.3.7",
"core-js": "^2.5.3",
"express": "^4.15.2",
"emailjs": "^1.0.10",
"jquery": "^3.2.1",
"linkify": "^0.2.1",
"linkifyjs": "^2.1.6",
"ng2-bootstrap": "^1.6.3",
"ngx-page-scroll": "^4.0.2",
"rxjs": "^5.2.0",
"socket.io-client": "^1.7.3",
"ts-helpers": "^1.1.1",
"web-animations-js": "^2.2.5",
"zone.js": "0.8.5"
},
"devDependencies": {
"#angular/cli": "~1.7.4",
"#angular/compiler-cli": "^5.2.0",
"#angular/language-service": "^5.2.0",
"#types/jasmine": "~2.8.3",
"#types/jasminewd2": "~2.0.2",
"#types/node": "~6.0.60",
"babel-polyfill": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"popper.js": "^1.14.3",
"protractor": "~5.1.2",
"request": "^2.81.0",
"smoothscroll-polyfill": "^0.4.0",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3"
},
"engines": {
"node": "9.x"
}
}
This is described in the common errors section of NPM's documentation:
Invalid JSON
Error: Invalid JSON
npm ERR! SyntaxError: Unexpected token <
npm ERR! registry error parsing json
Possible temporary npm registry glitch, or corrupted local server cache. Run npm cache clean and/or try again later.
This can be caused by corporate proxies that give HTML responses to package.json requests. Check npm's proxy configuration.
Check that it's not a problem with a package you're trying to install (e.g. invalid package.json).
Your package.json contains valid JSON. Try checking your package.lock.
In the end, this was to do with how I was pushing to heroku
Because I was on a branch, I should have been using:
git add .
git commit -m"message"
git push heroku <branchname:>master

Resources