20

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

> [email protected] 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.

1 Answer 1

45

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.

Sign up to request clarification or add additional context in comments.

3 Comments

^ this. I've been working with both GIT and Node ecosystem for years now, and it keeps tripping me up, thank you.
As of Git 2.0.1, the -f option is not needed.
Thanks a ton brother. I too had done a casing change long time back and now was getting this issue. Your post and answer saved me from insanity

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.