Especify BUILD Port for react JS - reactjs

When I run npm run build. And then run npm serve -s on the build folder. It outputs :
Local: http://localhost:5000
However I would that the application to run at localhost:3000. How do I specify that.

serve -s build -l specific port

Related

React App on Fargate is ignoring env variable

I deployed my React app and backend using Fargate with load balancers, I noticed my React app is using the wrong endpoint to access my API, it seems to be using the it's load balancer's DNS name as it's endpoint even though this endpoint is configured by using environment variables (On a React App, so this would be REACT_APP_API_URL).
On my local machine, this container works fine and is able to connect to my backend. Here it shows the correct endpoint.
If I were to run this same exact image in Fargate, the wrong endpoint is shown, this is actually the URL to visit my web app.
And I configured the correct endpoint in my task definition like so, it matches the correct endpoint shown in figure 1. I also made sure the service is using the latest task definition with this endpoint.
If needed this is my docker file.
# The first image is for compiling the client files, the second is for serving.
# BUILD IMAGE
FROM node:14-alpine as build-stage
WORKDIR /app
# Install dependencies
COPY package*.json ./
RUN npm install
RUN npm install cross-env -g
RUN npm install npm install #craco/craco -g
# Build
COPY . .
RUN npm run build
# -----------------------------------------------------------------------------
# SERVING IMAGE
FROM fitiavana07/nginx-react
# Copy built files
COPY --from=build-stage /app/build /usr/share/nginx/html
# 80 for HTTP
EXPOSE 80
# Run nginx
CMD nginx -g 'daemon off;'
Turns out I'm an idiot lol, you need a .env file at the root of your project, this means you can't pass environment variables to be docker image. I managed to overcome this by creating .env on my docker file like so.
# The first image is for compiling the client files, the second is for serving.
# BUILD IMAGE
FROM node:14-alpine as build-stage
WORKDIR /app
# Install dependencies
COPY package*.json ./
RUN npm install
RUN npm install cross-env -g
RUN npm install npm install #craco/craco -g
# Build
COPY . .
# Create a .env for react app
# Define a required build arg
ARG api_url
# Create a .env file
RUN touch .env
# Write the api url into the env file
RUN echo REACT_APP_API_URL=${api_url} > .env
RUN cat .env
RUN npm run build
# -----------------------------------------------------------------------------
# SERVING IMAGE
FROM fitiavana07/nginx-react
# Copy built files
COPY --from=build-stage /app/build /usr/share/nginx/html
# 80 for HTTP
EXPOSE 80
# Run nginx
CMD nginx -g 'daemon off;'
On my GitHub Actions, I use this action to dynamically set this build argument

An error occurs when npm run build with Docker

My simple Docker file in my Next.js project.
And start with this command >> docker build -f Dockerfile -t project-name . & docker build --tag project-name
enter image description here
But an error occurs like this picture when npm run build.
enter image description here
The important thing is not used "sharp" in my project.
Anyway I rebuild to docker when after install "sharp".
But Also error occurs when npm run install.
enter image description here
How can I build in docker Next.js project ?

is there anyway to start reactjs after build bundle?

I built my reactjs website with these command:
npm run build
After that, build folder is generated. To start server:
npm install -g serve
serve -s build
I want to run my react app background. Since i have no file *.js like:
nodemon lib/index.js --exec babel-node --presets=es2015,stage-2
from How to use nodemon in npm scripts to build and start scripts?
Any hint would be appreciated from my heart.
Thank a lot.

React serve -s build, The term 'serve' is not recognized as the name of a cmdlet

Hello I am trying to build my react app so I did yarn build and it created the necessary folder now I am trying to do serve -s build and it's telling me the error below
** I have tried to uninstall and reinstall serve by npm uninstall -g serve and npm install -g serve
and I found the serve folder in C:\Users\Nairi\AppData\Roaming\npm\node_modules
Try npx serve -s build I don't know why but they happened to me also and this worked
Solution1:
yarn global add serve
Based on NPM - Doc, you can install it globally yarn global add serve, then use it as you want like serve -s build
Solution2: npx:
npx serve -s build
As this article says, npx will check whether <command> or <package> exists in $PATH, or in the local project binaries(node_modules), and if so it will execute it, and if it's not there, it will download it. You can also run packages from github
Check your admin permissions, so it can install globally with the -g flag
I don't know if anyone still needs this but you can use this
yarn global add serve - Once this is successful, do yarn serve -s build. This worked for me!

Can't run mlflow standalone react server

I need to run the frontend UI on a separate server as a stand-alone react app (not with all of the mlflow python server and packages). But when I run the production build, I get the following error:
You need to enable JavaScript to run this app.
Reproduce:
git clone https://github.com/mlflow/mlflow.git
cd mlflow/mlflow/server/js
In development mode, "npm start" it works just fine:
npm install
npm start
But when I've run it in production, I am getting the above error.
npm install
npm install -g serve
npm run build
serve -s build
I tried many things searching in forums, including this one:
I am getting error in console "You need to enable JavaScript to run this app." reactjs.
but I didn't manage to make it work.

Resources