17

I have a GitHub workflow file for a Node.js project:

name: NodeJS CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.x]

    steps:
    - uses: actions/checkout@v2
    - name: Using Node version ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - run: npm ci
    - run: npm run build --if-present
    - run: npm test
    - name: Upload code coverage
      run: bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN
      env:
        CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

with a project structure as follows:

.
├── package-lock.json
├── package.json
├── src
│   ├── api
│   │   ├── calendar.js
│   │   ├── credentials.js
│   │   └── token.js
│   ├── app.js
│   ├── builders
│   │   └── event.js
│   ├── config
│   │   └── index.js
│   ├── loaders
│   │   ├── express.js
│   │   ├── index.js
│   │   └── mongo.js
│   ├── models
│   │   ├── credential.js
│   │   └── token.js
│   ├── scripts
│   │   └── tokenGenerator.js
│   └── services
│       ├── calendar.js
│       ├── credentials.js
│       ├── google.js
│       ├── mongo.js
│       └── token.js
└── tests
    ├── dbHandler.js
    └── services
        ├── calendar.js
        ├── google.js
        └── mongo.js

Locally, when I run npm test, my tests pass with no reported problems. However, when the tests run on Github Actions, I get the following error:

Run npm test

> my-repo@1.0.4 test /home/runner/work/my-repo/my-repo
> nyc --reporter=html mocha 'tests/**/*.js' --exit


Error: Cannot find module '../models/credential'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/home/runner/work/my-repo/my-repo/src/services/mongo.js:2:140)
etc..

Where the file in question has relative requires:

const CredentialSchema = require('../models/credential');
const TokenSchema = require('../models/token');

I've tried a number of things:

  • using process.cwd() along with the rest of the folder structure to get an absolute file path
  • appending .js to the require
  • different versions of node
  • same version of node on my machine and in the Github Action

but nothing seems to resolve the error. My node_modules folder is ignored in .gitignore.

The repo is private, but I don't think that has anything to do with it.

Tom
  • 2,372
  • 4
  • 25
  • 45

1 Answers1

37

Turns out git hadn't detected a case sensitive change in my file.

Running git mv -f src/models/Credential.js src/models/credential.js and then pushing the changes fixed it.

Tom
  • 2,372
  • 4
  • 25
  • 45