0

I built the follow Docker container

FROM node:20-alpine as ember
WORKDIR /usr/app
COPY package*.json /usr/app/
RUN apk fix && \
    apk --no-cache --update add git && \
    npm clean-install

and uploaded to a registery.

npm run built works as expected from docker compose up with compose.yaml as

services:
  frontend:
    image: my-docker-image
    volumes:
      - type: bind
        source: .
        target: /usr/app
    command: npm run build

When I try to run npm run build from GitLab CI, I get the error sh: ember: not found. The GitLab CI task/job is

npm-run:
  image: my-docker-image
  script:
    - npm run build

Why npm is not working in GitLab CI?

2

1 Answer 1

0

GitLab CI overwrite Docker's WORKDIR to /builds/username/repository. Because of this, the current directory (/builds/username/repository) did not have the node_modules as it was installed in /usr/app/ and npm run built fails.

In the local machine, the development node_modules also overwrite the node_modules in the Docker container. Because of this, npm run built runs as expected.

Change my GitLab CI configuration to

npm-run:
  image: my-docker-image
  script:
    - ln -s ../../../usr/app/node_modules node_modules
    - npm run build

resolved the problem.

Additional note: Change my GitLab CI configuration to

npm-run:
  image: my-docker-image
  script:
    - npm run --prefix ../../../usr/app build

did not resolved the problem because --prefix ../../../usr/app is equivalent to cd ../../../usr/app and npm couldn't find my project files.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.