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.
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?
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
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.
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