projects.map is not a function for jest-cli

javascript, jestjs, reactjs, typescript

Solution

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:

...(/Users/DavidHu/.nvm/versions/node/v6.2.1/lib/node_modules/jest-cli/bin/jest.js:16:25)

Jest from the project:

...(/Users/DavidHu/Desktop/coding/projects/swapnow/node_modules/jest-cli/build/cli/runCLI.js:172:28)

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.

Problem

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: projects.map 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 Object.run (/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": [ "ts", "tsx", "js" ] } ``` Has anyone encountered this error and know how to fix it?

Original source