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"
}
Related
Hi I am trying to deploy node js app on AWS Elastic Beanstalk. However I am not able to deploy the same. Every-time the build fails.
Getting below error:
During an aborted deployment, some instances may have deployed the new application version. To ensure all instances are running the same version, re-deploy the appropriate application version.
Sharing part of package.json for reference.
"scripts": {
"start": "node server.js",
"server": "nodemon server",
"client": "npm start --prefix client",
"debug": "ndb server.js",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"test": "mocha --recursive --timeout 20000 --exit",
"heroku-postbuild": "cd client && NPM_CONFIG_PRODUCTION=false npm install && npm run build"
},
I have a web app that uses Express backend and React frontend. The heroku-postbuild script in my package.json is as follows:
"heroku-postbuild": "npm run build && cd frontend && npm install && npm run build"
When I git push heroku master all seems to be fine until I get:
"Failed at the honeyman-designs#1.0.0 heroku-postbuild script."
this is the script:
"scripts": {
"start": "nodemon --watch backend --exec babel-node backend/server.js",
"build": "del -rf dist && babel backend -d dist",
"heroku-postbuild": "npm run build && cd frontend && npm install && npm run build"
},
The script inside frontend is:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
I'm using Windows 10 as my OS.
My Procfile contains:
web: node dist/server.js
I'm not too sure what I'm doing to get this error if anybody can help it would be appreciated.
I have simple custom starter pack react-create-app and Electron.js.
I have added to package.json file:
"scripts": {
"electron": "electron .",
"start": "cross-env BROWSER=none react-scripts start",
....
and I can start Electron with npm run electron and React with - npm start.
What I want is to start React and Electron just with one command like: npm run both.
I have tried:
"both": "\"npm start\" \"npm run electron \"",
but I am getting an error in a log file:
Exit status 1 node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
- nothing specific
I have tried and:
"start": "npm run electron . && cross-env BROWSER=none react-scripts start",
, but this starts the Electron, when I close it, it start the React app.
Again error:
"electron": "electron .",
"start": "cross-env BROWSER=none react-scripts start",
"both": "\"npm run electron\" \"npm run start\"",
I don't know, how to start react-create-app and Electron with just one NPM command ?
Consider utilizing concurrently.
cd to your project directory and run the following command to install it:
npm i -D concurrently
Then redefine the both script in the scripts section of your package.json as follows:
"both": "concurrently \"npm start\" \"npm run electron\""
or the slightly shortened equivalent:
"both": "concurrently \"npm:start\" \"npm:electron\""
I would like to run one npm start command to run both my frontend folder and backend folder. Currently, I have to navigate inside each folder and individually run the command on both to see my app open on the localhost. I have looked into the package 'concurrently' but am having some trouble implementing it in my package.json file.
Here is my package.json file for my frontend folder:
"scripts": {
"start": "set HOST = 'http://localhost' && set PORT=8000 && react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"postbuild": "react-snap"
}
I have tried using this bit to run the backend once I run npm start on the frontend however it did not work:
"start": "set HOST = 'http://localhost' && set PORT=8000 && ../backend/ start & react-scripts start"
Edit:
Still having some troubles after reattempting.
Here are my scripts from my package.json files
Frontend folder
"scripts": {
"start": "set HOST = 'http://localhost' && set PORT=8000 && react-scripts start",
"build": "react-scripts build",
"test": "jest",
"eject": "react-scripts eject",
"postbuild": "react-snap"
},
Backend Folder
"scripts": {
"start": "node ./bin/www"
},
The front end is written in React and the backend in Node. Any help would be greatly appreciated!
Install concurrently:
npm i concurrently --save-dev
Now go to your package.json and add this:
"start": "node index.js",
"client": "npm run start --prefix client",
"dev": "concurrently \"npm run start\" \"npm run client\""
(assuming your client folder contains the front-end server)
then, if you wanna run both servers, just type npm run dev and be happy
I was facing the same issue but it is resolved now. Let's say the server is in the 'Backend' folder and the frontend is in the 'client' folder.
then scripts in server-side package.json should be like:
"scripts": {
"client-install": "npm install --prefix client",
"start": "node server.js",
"server": "nodemon server.js",
"client": "cd ../ && npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
and client-side package.json is like:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:5000",
then 'npm run dev' runs concurrntly both the server
The 'concurrently' package can do this
npm i concurrently --save-dev
Then set up npm run dev to do
"dev": "concurrently --kill-others \"npm run start-watch\" \"npm run wp-server\""
Another option is to do (Running in Windows CMD):
"dev": "start npm run start-watch && start npm run wp-server"
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.