An error occurs when npm run build with Docker - reactjs

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 ?

Related

Unable to run cypress in docker reactjs project - Please reinstall Cypress by running: cypress install

I spent two days just figuring out running cypress in a docker so I can test it locally. Here is the Dockerfile
FROM cypress/base:16 as UIbuilder
ENV NODE_ENV development
WORKDIR /opt/app
COPY custom-ui .
RUN npm install
RUN npm run build
RUN npm pack
FROM cypress/base:16 as APPbuilder
ARG REACT_APP_PORTAL_API
ARG REACT_APP_ENVIRONMENT="production"
ENV REACT_APP_PORTAL_API=$REACT_APP_PORTAL_API
ENV REACT_APP_ENVIRONMENT=$REACT_APP_ENVIRONMENT
WORKDIR /opt/app
ENV APP_DIR /opt/app/
COPY . .
# Build App
COPY --from=UIbuilder /opt/app/*.tgz .
RUN npm install ./*.tgz --legacy-peer-deps
RUN chown -R node /opt/app/node_modules
RUN npm install
USER node
RUN npx cypress verify
# CMD ["ws", "--directory", ".", "--spa", "index.html", "--log.format", "combined"]
EXPOSE 3000
CMD ["npm","start"]
And here is the docker-compose.dev.yml file
version: "3.7"
services:
app:
container_name: frontend
image: frontend
build: .
env_file:
- .env.dev
ports:
- "3000:3000"
volumes:
- .:/opt/app:rw
- /opt/app/node_modules
- ./project-cypress/cypress:/opt/app/cypress
- ./project-cypress/cypress.config.js:/opt/app/cypress.config.js
environment:
- CYPRESS_baseUrl=http://app
command: npx cypress run
Here is the project directory is structured, a reactjs project
frontend
custom-ui
build
cypress
e2e
fixtures
screenshots
support
videos
public
src
....
cypress.config.js
Every time I run docker-compose -f docker-compose.dev.yml up --build
I got the following errors
Step 21/23 : RUN npx cypress verify
---> Running in 9c2b1398e724
No version of Cypress is installed in: /home/node/.cache/Cypress/10.8.0/Cypress
Please reinstall Cypress by running: cypress install
----------
Cypress executable not found at: /home/node/.cache/Cypress/10.8.0/Cypress/Cypress
----------
Platform: linux-x64 (Debian - 11.3)
Cypress Version: 10.8.0
ERROR: Service 'app' failed to build : The command '/bin/sh -c npx cypress verify' returned a non-zero code: 1
Any ideas about what I'm done wrong?
regards
In your package.json file try to add
"cy:run": "cypress install && cypress run"
In a docker-compose.dev.yml file in the command section run cy:run.
command: npm run cy:run
I know it's weird you may ask yourself why you should run a cypress install if you use a cypress image.. but I had the same problem, and this helped me.

React production build is returning 404 error

npx create-react-app app-name
cd app-name
npm start
works fine but
npm run build
cd build
serve -s build
return 404
It's inbuilt react code. I have not changed anything.
running in the development server but not in the production server.
Is there anything am I doing wrong here?

Especify BUILD Port for react JS

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

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.

npm run build not creating build folder for production server

I am running command npm run build for making build for the production server. But it is not creating build folder.
$ npm run build
I am attaching image of result after run npm run build command

Resources