Run npm build after beanstalk deploy - node.js

Anyone know how to get node AWS beanstalk to run npm run build command after its does its npm install.
I have the following scripts in my package.json but it doesn't seem to run the build or the start command just the install
"scripts": {
"build": "cross-env NODE_ENV=production webpack --config ./webpack/webpack.prod.config.js --progress --colors",
"start": "node server/app.js",
"dev": "nodemon server/app.js"
},

Related

Custom script in NPM package.json is ignored, runs as standalone

in my package.json I have these scripts:
"scripts":
{
"lint": "./node_modules/.bin/eslint src",
"build": "npm run clean && npm run dev && npm run prod",
"tsc": "./node_modules/.bin/tsc",
"dev": "./node_modules/.bin/webpack --config webpack.dev.js",
"prod": "./node_modules/.bin/webpack --config webpack.prod.js",
"clean": "del /q inet-henge*.js* dist",
"watch": "./node_modules/.bin/webpack --config webpack.dev.js --watch",
"postinstall": "copy inet-henge.js \"..\\flask\\customer_topology\\static\""
}
But for some reason postinstall is completely ignored when i run npm run build. When I run it as standalone script, it runs, the file is copied to the new location. Path is correct. What could be the problem, I am on Windows
post<x> runs after <x> so postinstall runs after install and if you want a script to run after build it should be called postbuild See https://docs.npmjs.com/cli/v6/using-npm/scripts for more details.

how to configure "npm run-script build" command in Nodejs package.json

I am trying to deploy nextjs based project on AWS EBS, but it is not able to run script "npm run-script build" on server, by this it makes nextjs based build package folder and can run app. here my json.
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "cross-env NODE_ENV=production node server.js"
}
when I deployed my app on server it gives following error.
Error: Could not find a valid build in the '/var/app/current/.next' directory! Try building your app with 'next build' before starting the
server.
I need to run command "npm run-script build" before running app on server, but dosen't aware how to achieve this
simply we can run multiple commands at a time.
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "npm-run-script-build && cross-env NODE_ENV=production node server.js"
}

NPM command for run Node server after webpack finish building

I want to run a command like: npm run start:dev to make my node server runs but after webpack finished building bundles.
My current npm scripts are:
"scripts": {
"start": "node server/server.js",
"start:dev": "npm run build:prod & npm start",
"lint": "eslint *",
"build:dev": "webpack",
"build:prod": "webpack -p --env production",
"dev-server": "webpack-dev-server",
"test": "cross-env NODE_ENV=test jest --config=jest.config.json"
},
The current command will kick both operations together.
Typo: you don't actually want to use &, you want &&:
"start:dev": "npm run build:prod && npm start",
A single ampersand will background the run:build job and cause start to run concurrently.

Getting "Cannot find module '/app/dist'" error on deploying to Heroku

I have the following script in my package.json:
"scripts": {
"dev": "nodemon server --exec babel-node --presets es2015,stage-2",
"build": "babel ./server -d ./dist",
"start": "node ./dist",
"heroku-postbuild": "cd react-ui/ && npm install && npm install --only=dev --no-shrinkwrap && npm run build"
},
On deploying to Heroku I get the following error
Error: Cannot find module '/app/dist'
On local npm run dev, npm run build, and npm run start work fine.
Where is it getting the /app folder? How to fix this?
Thanks
Matloob
You should build your app npm run build before deploy to heroku. It will run heroku-postbuild first then start your app.
Try this :
"start:heroku": "node dist/YOUR-APP-NAME/server/main.js",

Node Application Heroku Application Error

I am using heroku/nodejs build pack.
this is how my scripts in package.json look like:
"scripts": {
"build": "webpack --config webpack.prod.js",
"server": "http-server public -p 3000 -a localhost -c 0",
"prod": "npm run build && npm run server",
"dev": "webpack-dev-server --config webpack.dev.js",
"lint": "eslint . --fix"
},
In procfile I have only one line of code:
web: npm run prod
Any ideas why am I seeing application error?
In regards to the error, I think that you should be using the environment variable $PORT i.e. http-server public -p $PORT -c 0 Make sure you have http-server in you deps and not your devDeps.
This might not be causing the error but you shouldn't do your build on run. Instead add the build step to a postinstall NPM script like below.
"scripts": {
"build": "webpack --config webpack.prod.js",
"postinstall": "npm run build",
"server": "http-server public -p $PORT -c 0",
"prod": "npm run server",
"dev": "webpack-dev-server --config webpack.dev.js",
"lint": "eslint . --fix"
},
This will ensure that your build gets run on deployment and not every time the node process starts.

Resources