Push rejected, failed to compile Node.js app while deploying in heroku - node.js

i am deploying my django+react app on heroku but its raising this error every time
Push rejected, failed to compile Node.js app
i have tried every thing remove cache delete package-lock.json update the node version according to .env file and other packages , app working fine in local but not deploying on server.i have this error so far at every time please help me to resolve i have also follow the heroku documentation to resolve this issue but not worked for me.

i have resolved my issue by little bit changing into my package.json file
before:
scripts": {
"start": "cd frontenduser && npm install && webpack-dev-server --env.NODE_ENV development",
"build": "cd frontenduser && npm install && webpack --env.NODE_ENV production",
"test": "jest --watch" },
after:
scripts": {
"start": "cd frontenduser && npm install ",
"build": "cd frontenduser && npm install",
"test": "jest --watch" },

Related

Docker / Node.js / Vue.js -> error:0308010C:digital envelope routines::unsupported

I try to set up a docker image for a program based on Vue.js.
Unfortunately I get the Error: error:0308010C:digital envelope routines::unsupported
I already tried the following solutions, unfortunately without success:
Added "start": "react-scripts --openssl-legacy-provider start" in package.json RESULT: No Change, still error:0308010C
Added "build": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build" in package.json RESULT: Error changed to executor failed running [/bin/sh -c npm run build]: exit code: 127
changed dockerfile to use an older node.js version: FROM node:node:lts-alpine as build RESULT: Error changed to Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
What else can I try to get my Vue.js program into a docker image?
The script part of my package.json file (before my above mentioned unseccessfull changes) looks like this:
"scripts": {
"dev": "NODE_ENV=development nodemon -w backend/app.js backend/app.js & vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"start": "node backend/app.js"
},
The first lines of my dockerfile (before my above mentioned unseccessfull changes) looks like this:
FROM node:current-alpine as build
RUN ["mkdir", "-p", "/usr/src/app"]
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json", "/usr/src/app/"]
RUN apk add --no-cache git &&
npm install
COPY . .
RUN npm run build
Any help is highly welcome.

Heroku not running the postinstall or heroku-postbuild commands:

I'm trying to deploy an app that makes use of the MRE SDK to Heroku. As of this writing, the SDK itself is broken, and attempting to run an npm run build will result in an error.
A work around is to copy a modified animation.d.ts file over to the resulting node_modules folder, after the install (specifically ./node_modules/#microsoft/mixed-reality-extension-sdk/built/animation/).
I keep this file in a folder called v0.16_mre_fix.
Without this, the build will fail. So I added this to my package.json file.
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"clean": "tsc --build --clean",
"heroku-postbuild": "cp -i ./v0.16_mre_fix/*.ts ./node_modules/#microsoft/mixed-reality-extension-sdk/built/animation/",
"build": "tslint -p ./tsconfig.json src/**/*.ts && tsc --build",
"lint": "tslint -p ./tsconfig.json src/**/*.ts",
"start": "node .",
"debug": "node --nolazy --inspect-brk=9229 ."
},
According to heroku here, heroku-postbuild will be run after installing dependencies. This, however, did not work.
So I tried changing it to heroku-prebuild and postinstall:. They didn't work either.
Am I missing something?
EDIT: I also tried
"heroku-prebuild": "echo This runs before Heroku installs your dependencies.",
but I didn't see any echo in the ensuing git push.

package.json scripts failing on heroku

So I have a series of scripts that are set up to either dev servers for a React/Node Express application OR a production server on heroku. The structure of the app is as follows:
client/package.json //pckg for react app
package.json //pckg for the node server
these are the scripts in the clients package:
"scripts": {
"start": "if-env NODE_ENV=production && npm run start:prod || npm run start:dev",
"start:prod": "node server.js",
"start:dev": "set NODE_ENV=development&& concurrently \"nodemon --ignore 'client/*'\" \"npm run client\"",
"client": "cd client && npm run start",
"seed": "node scripts/seedDB.js",
"install": "cd client && npm install",
"build": "cd client && npm run build",
"heroku-postbuild": "npm run build"
}
and the only difference between the react apps package.json and the one that is automatically generated with create-react-app is as follows:
"proxy": "http://localhost:3001/",
the way its supposed to run is, install scripts at root folder, run install script to cd into client and install react apps dependencies, then heroku's post-build script should kick in to run the build script which cds into client and builds a production ready react app. finally the start script should see a NODE_ENV of production and run start:prod.
my problem is that for some reason when i push to heroku, it seems to get stuck on an infinite loop on the install script. I have NO clue why, as the exact same scripts work on other projects PERFECTLY.
https://github.com/LordKriegan/reactdbdemo
https://github.com/LordKriegan/reactdbdemo2/ if anyone wants to look at it. (doing a full stack demo for my students :/ not much of a demo if i cant get it deployed)
I got it working. Forgot create-react-app also initializes a git repo...? either that or somewhere along the way i did an extra git init. anyways i had a .git folder in my client folder, which was preventing my client folder from being pushed up. i ended up creating a new repo and pushing everything to that one and now it works. so incase anyone comes here with a similar problem... make sure you didnt end up in some kind of gitception trap. :/

Deploy on AWS ElasticBeanstalk - run custom npm script before starting server?

I have been trying to deploy my nuxt universal app onto AWS elastic beanstalk. I've tried using custom npm script in my package.json:
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
"precommit": "npm run lint",
"deploy": "nuxt build && nuxt start"
},
Then under AWS EB config, i added Node command: npm run deploy
However, it is not working.
Basically, i need to tell EB to run "npm run build" before "npm run start"
Anybody can help?
What you've described lies in the npm realm, and can be solved by using a prestart script, like so:
"prestart": "nuxt build"
More details here: https://docs.npmjs.com/misc/scripts
So far this has helped me, it seems to work for default nuxt project (nuxt create) in universal mode.
I am using Elastic Beanstalk, CodePipeline and Bitbucket.
CodePipeline takes code from Bitbucket once it is pushed and builds in on Elastic Beanstalk.
What helped me is adding to package.json:
"deploy": "npm run build && npm run start"
or
"deploy": "npm run install && npm run build && npm run start"
and creating Procfile in root directory of project, content/command of Pocfile triggers the deploy script in package.json file
web: npm run deploy
Before, there were "hooks" but now they're almost deprecated https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/custom-platform-hooks.html
Now you can use Buildfile and Procfile as described here https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html
Try Adding to your .ebextensions a "source_compile.config" file as follows:
# source_compile.config
container_commands:
compile:
command: "./node_modules/.bin/nuxt build"
env:
PATH: /opt/elasticbeanstalk/node-install/node-v12.16.3-linux-x64/bin/
Got the idea from the same need to pre compile a typescript nodejs server before deploying to Elastic Beanstalk :)
Here a ref:
https://medium.com/#lhviet88/deploy-a-typescript-expressjs-into-elasticbeanstalk-nodejs-server-8381e00e7e52

Using Nodemon or something similar to listen for changes, first build, then start?

Using Nodemon or something similar to listen for changes, first build, then start? Is it possible?
"scripts": {
"build": "npm run build:dll && webpack --progress",
"start": "node app.js",
}
Make sure nodemon is installed (npm install -g nodemon or npm install --save-dev nodemon) and then just change your package.json to this:
"scripts": {
"build": "babel lib -d build --copy-files",
"start": "nodemon build/index.js"
}
EDIT:
Add a nodemon.json on the root of your project, in there insert your build script in the "events.restart" section as documented here: https://github.com/remy/nodemon/blob/master/doc/sample-nodemon.md
"events": {
"restart": "your build script here"
}
And finally run with "npm run start". This run your app with nodemon and nodemon's configuration will execute your build very time you change your code (on restart)

Resources