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.
Related
Compiling takes more than 20-22 seconds. I trying to improve the compiling speed of typescript node backend.
I'm using windows 11 bash terminal, computer not very bad (Intel(R) Core(TM) i7-9750H CPU # 2.60GHz, 2592 Mhz, 6 Core, 12 thread). Same build completes much faster on macOS.
Here is the my scripts;
"scripts": {
"start": "npx ts-node",
"dev": "npx nodemon --watch src src/index.ts",
"production": "npx ts-node ./src/index.ts",
"build": "npx tsc -p tsconfig.json && npx tscpaths -p tsconfig.json -s ./src -o ./build",
"build:run": "npm run build && npm run production",
"lint": "tslint -c tslint.json --project tsconfig.json",
"test": "jest --config jest.config.js",
"watch": "npm run build && npm run start",
"watch:lint": "npm run lint -- --watch",
"watch:test": "npm run test -- --watch",
"watch:build": "npm run build -- --watch",
"watch:start": "npm run start -- --watch"
},
What would you recommend me?
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.
I have express.js application, and I want to run command build before application starts, but I am getting this error "Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch".
Here is my scripts in package.json
"scripts": {
"dev": "concurrently \"webpack --config webpack/client.prod.js --progress --watch\" \"webpack --config webpack/server.prod.js --progress --watch\" \"npm start\"",
"real_dev": "webpack-dev-server --config webpack/client.dev.js",
"build": "npm run build:client && npm run build:server",
"build:server": "cross-env NODE_ENV=production webpack --config webpack/server.prod.js --progress",
"build:client": "cross-env NODE_ENV=production webpack --config webpack/client.prod.js --progress",
"start": "cd server && node bin/server.js",
"lint": "eslint --ext .jsx,.js ./"
},
Try to use port from env with process.env.PORT instead of static port
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.
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"
},