githubgithub-actions

Github actions: Dependencies lock file is not found in runners/path


I have a single Github repository for both server and frontend. The directory structure looks like:

root
  |- frontend
  |- server (Express App)

Github Action:

name: Node.js CI

on:
  push:
    branches: [ main ]

jobs:
  build:

    runs-on: self-hosted
        
    strategy:
      matrix:
        node-version: [14.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v2
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'npm'
    - run: npm ci
      working-directory: './server'
    - run: npm run start
      working-directory: './server'

I only have a single job to build the Express server (and not the frontend yet) so I set the working-directory to ./server. However, I still get an error:

Dependencies lock file is not found in /home/{username}/runners.../repository_name. Supported file patterns: package-lock.json,yarn.lock

So apparently it's not trying to run in .../reposirtoy_name/server.

enter image description here

I'm just trying to build both server and frontend in single Github action.


Solution

  • There might be a chance that your problem is specifically with "uses: actions/setup-node". They mention in the docs that if you have multiple lock files or a lock file(s) in a directory that is not the root

    In my case I had a single project with nested projects/dir. In my GitHub actions I wanted to run npm test on the nested project/dir so I had to specify to use my package.json inside the specific sub-directory. Double check to see that you are specifying the right directories with cache-dependency-path.

    steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-node@v4
      with:
        cache-dependency-path: subdir/package-lock.json
        node-version: 20
        cache: 'npm'
    - run: npm ci
    - run: npm test
    

    Specified here
    https://github.com/actions/setup-node#caching-global-packages-data