Restoring cache error

I’m completely new to circle CI, I managed to sign up for an account and linked my GitHub, I selected a repo, added the code that was provided, pushed the .circleci folder with config.yaml in it and I get an error
error computing cache key: template: cacheKey:1:30: executing "cacheKey" at <checksum "~/project/package-lock.json">: error calling checksum: open /home/circleci/project/package-lock.json: no such file or directory
My config file is the one circle suggested

version: 2.1
orbs:
  node: circleci/node@3.0.0
workflows:
  node-tests:
    jobs:
      - node/test

So I look in the docs and find this code snippet that looks like it may do the job

      - restore_cache:
          name: Restore Yarn Package Cache
          keys:
            - yarn-packages-{{ checksum "yarn.lock" }}
      - run:
          name: Install Dependencies
          command: yarn install --immutable
      - save_cache:
          name: Save Yarn Package Cache
          key: yarn-packages-{{ checksum "yarn.lock" }}
          paths:
            - ~/.cache/yarn

but I don’t understand where in the config.yaml it should go? or can I just use pkg-manager: yarn but again where in the config.yaml does it go?

Why didn’t circle ci detect i had a yarn.lock in the repo and give me the correct yaml to upload? It would have guaranteed success instead of failure when trying circle for the first time.

Hi @bkawk Welcome to the community!

I see you’re using the nodej orb which is a more stream lined way to implement functionality. The nodejs orb has functions that accomplishes what you’re attempting. Please checkout the nodejs orb docs specifically the cache elements in the install-packages orb command. The cache mechanisms for the can be controlled via those properties.

Also please provide more feedback on you’re experience. We’re very interested in feedback so we can continually improve functionality.

So in your steps, make sure to have the node/install-packages pkg-manager option set to ‘yarn’ like so:

  steps:
      # Checkout the code as the first step.
      - checkout
      # Next, the node orb's install-packages step will install the dependencies from a package.json.
      # The orb install-packages step will also automatically cache them for faster future runs.
      - node/install-packages:
          pkg-manager: yarn
      - run:
          command: yarn test
          name: Run YARN tests

maybe, you should add package-lock.json to your repo :slight_smile:

1 Like