Source:  Twitter logo

I am writing a react app and testing it with jest. However, whenever I run the jest command from the terminal, I keep this error.

TypeError: is not a function
    at Object.<anonymous> (/Users/DavidHu/Desktop/coding/projects/swapnow/node_modules/jest-cli/build/cli/runCLI.js:172:28)
    at next (native)
    at step (/Users/DavidHu/Desktop/coding/projects/swapnow/node_modules/jest-cli/build/cli/runCLI.js:18:30)
    at /Users/DavidHu/Desktop/coding/projects/swapnow/node_modules/jest-cli/build/cli/runCLI.js:34:14
    at Object.<anonymous> (/Users/DavidHu/Desktop/coding/projects/swapnow/node_modules/jest-cli/build/cli/runCLI.js:15:12)
    at Object.module.exports [as runCLI] (/Users/DavidHu/Desktop/coding/projects/swapnow/node_modules/jest-cli/build/cli/runCLI.js:2 03:17)
    at (/Users/DavidHu/.nvm/versions/node/v6.2.1/lib/node_modules/jest-cli/build/cli/index.js:42:17)
    at Object.<anonymous> (/Users/DavidHu/.nvm/versions/node/v6.2.1/lib/node_modules/jest-cli/bin/jest.js:16:25)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)

I went into node_modules to look at the line of code that is causing the error, projects is a string of the project current path.

Here is my jest configuration in package.json

  "jest": {
    "transform": {
      ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "moduleFileExtensions": [

Has anyone encountered this error and know how to fix it?

Just ran into the same problem. If you look at your stack trace closely you'll notice that you run two different Jest setups:

Globally installed jest:


Jest from the project:


They are probably have different (and incompatible) versions. If you remove jest from your project (or from global node_modules) that should solve the problem.

16 users liked answer #0dislike answer #016
jafrog profile pic

This will happen if you update jest in your project but run it using just jest from the command line (not from node_modules).

To fix you'll need to update your global jest:

npm install -g jest

7 users liked answer #1dislike answer #17
Rick Hanlon II profile pic
Rick Hanlon II

I had the same issue. I was passing a string to the 'projects' parameter instead of an array.

Wrapping the string 'projectPath' in [] fixed it for me (this is located inside a Gulp task):

var jestCLI = require('jest-cli');
jestCLI.runCLI({'onlyChanged': true}, [projectPath], callback);
3 users liked answer #2dislike answer #23
Koen profile pic

I ran in to the same issue with local and project installations of jest-cli. I removed the project installation of jest-cli and got the issue resolved.

0 users liked answer #3dislike answer #30
Anuradha profile pic

Copyright © 2022 QueryThreads

All content on Query Threads is licensed under the Creative Commons Attribution-ShareAlike 3.0 license (CC BY-SA 3.0).