Checkout code overwriting node_modules generated during image build

I have a very basic image that runs a yarn command when built (see below). Locally, this creates the node_modules directory and populates it with the appropriate packages. That said, the ‘Checkout code’ step in my CircleCI build seems to be overwriting everything, ultimately removing the node_modules directory. As such, subsequent commands such as yarn jest fail with a ‘command not found’ error. Am I misunderstanding something? It doesn’t make sense that I would have to run yarn in a subsequent step if the image itself ran that command at build time. Note: I’ve redacted the image name for privacy.

Dockerfile

FROM myimage
COPY package.json yarn.lock ./
RUN yarn

.circleci/config.yml

version: 2
    jobs:
      build:
        docker:
          - image: myimage

    steps:
      - checkout

      - run:
          name: Run Jest
          command: yarn jest

Any help is much appreciated, thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.