Jacob Clark
Jacob Clark

Reputation: 3437

Travis-CI cannot find relative module require

I have a Travis build job that is running mocha tests, however the build is failing with the error:

Error: Cannot find module './sources/reddit'

My file tree is the following

feeds/ 
     sources/ 
          Reddit.js
     Feeds.js
app.js

Within Feeds.js I am doing

var https   = require('https'),
    q       = require('q'),
    Reddit  = require('./sources/reddit');

However it seems to be flagging up an error loading it up.

Upvotes: 4

Views: 1942

Answers (4)

Dmytro
Dmytro

Reputation: 5701

I ran into this insane case mismatch on MacOS:

  • Locally dir name is in lower case: landing (checked with Finder, terminal and VS Code)
  • On GitHub the first letter is in upper case: Landing

Of course, no CI can handle that: both Travis and CircleCI failed to build.

A solution for GitHub case mismatch:

  • rename your file/dir to something else like file1 and commit changes
  • rename it back and commit changes

Upvotes: 0

tinesoft
tinesoft

Reputation: 766

To complete others's responses, another situation where you can run into a similar issue on CI, is simply that your required files are ignored from Git. So locally, there are tthere, but not when Travis builds.

So make sure there is no rule in your .gitignore that prevents those files to be checked in.

Upvotes: 2

Spencer Jones
Spencer Jones

Reputation: 41

I also just ran into this issue, but the capitalization issue was harder to detect.

When I first checked the file into git, it was named container.js (lower-case "c"). I subsequently changed it to Container.js, so it reflected the upper-case name on my file-system.

Git, however, doesn't detect the case change on case-insensitive OSs so every time travis-ci runs, it ran against the lower-case name and so failed the build. (See Changing capitalization of filenames in Git for details on how to do this properly)

I solved this by simply renaming the file and changing all references so that git picked up the new name.

Upvotes: 4

Jacob Clark
Jacob Clark

Reputation: 3437

This error is because I was referencing ./sources/reddit with reddit as lowercase, on the filesystem the file is Reddit with an uppercase R.

Mac OSX deals with case sensitivity well, Linux does not.

Upvotes: 11

Related Questions