Error: uncaughtException: Cannot find module 'Joi'

This is my config.yml file

# Javascript Node CircleCI 2.0 configuration file
# Check for more details
version: 2
    - mongodb
      # specify the version you desire here
      - image: circleci/node:8.11.1
      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at
      - image: circleci/mongo:3.4.15

    working_directory: ~/repo

      - checkout

      # Download and cache dependencies
      - restore_cache:
          - v1-dependencies-{{ checksum "package.json" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-
      - run: yarn install

      - save_cache:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}
      # run tests!
      - run: yarn test

But whenever I run the build it exits with code 1 on CircleCI
With Error log as:

yarn run v1.5.1
$ nyc mocha --timeout 10000 --exit
19:56:59 - error: uncaughtException: Cannot find module 'Joi' date=Thu Sep 06 2018 19:56:59 GMT+0000 

My package.json file seems to have JOI defined and also the test cases run fine on local machine.

  "name": "crm-dcr-api",
  "main": "server.js",
  "repository": {
    "type": "git",
    "url": ""
  "scripts": {
    "start": "nodemon server.js",
    "test": "nyc mocha --timeout 10000 --exit",
    "test-coverage": "istanbul cover _mocha -- -u exports -R spec --exit",
    "sync": "node ./jobs/",
    "gulp": "gulp"
  "author": "Sourav Lahoti",
  "license": "MIT",
  "dependencies": {
    "app-module-path": "^2.2.0",
    "async-redis": "^1.1.4",
    "body-parser": "~1.18.2",
    "cli-table": "^0.3.1",
    "compression": "^1.7.3",
    "express": "~4.16.1",
    "g": "^2.0.1",
    "getenv": "^0.7.0",
    "gulp": "^3.9.1",
    "gulp-mocha": "^5.0.0",
    "https": "^1.0.0",
    "joi": "^13.6.0",
    "jsonwebtoken": "^8.2.1",
    "lodash": "^4.17.10",
    "mocha-junit-reporter": "^1.17.0",
    "mongoose": "~4.11.14",
    "morgan": "~1.9.0",
    "node-fetch": "^2.1.2",
    "node-schedule": "^1.3.0",
    "nodemon": "^1.17.4",
    "query-params-mongo": "^1.0.4",
    "querystring": "^0.2.0",
    "request": "^2.85.0",
    "request-promise": "^4.2.2",
    "winston": "^2.4.1"
  "devDependencies": {
    "chai": "^4.1.2",
    "istanbul": "^0.4.5",
    "mocha": "^5.0.5",
    "nyc": "^11.6.0",
    "supertest": "^3.0.0"

What’s the output of your yarn install? Maybe that failed.

It may be worth examining your working directory to see if your dependencies are actually in node_modules. I assume the cache in meant to restore them - did it? I’d suggest using the SSH rebuild feature in the CircleCI build UI to find out.

I have checked the node_modules I see Joi being installed

OK. Readers are probably going to need more than that to help. What else have you got? :smile_cat:

You wouldn’t believe but I change my code from
let Joi = require('Joi')
let joi = require('joi')
all small-case, surprisingly it fixed the build.
But I am guessing y it worked locally :thinking:

Ooh, nice. Is your local file system case insensitive? Are you on a Windows dev machine?

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.