jest: Cannot find module 'setupDevtools' from 'setup.js' - Platform Windows

Do you want to request a feature or report a bug?

bug

What is the current behavior?

When i run the tests on a linux maschine everything is fine. When i run the tests with the same configuration on my windows computer the following error is thrown:

Cannot find module 'setupDevtools' from 'setup.js'

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

OS - Windows

package.json

{
  ...
  "dependencies": {
    "react": "16.0.0-alpha.12",
    "react-native": "0.45.1",
    "react-native-mirror": "0.0.19"
  },
  "devDependencies": {
    "babel-jest": "20.0.3",
    "babel-preset-react-native": "1.9.2",
    "cross-env": "^5.0.0",
    "jasmine-reporters": "2.2.1",
    "jest-cli": "20.0.4",
    "react-native-cli": "^2.0.1",
    "react-test-renderer": "16.0.0-alpha.13"
  },
  "jest": {
    "collectCoverage": true,
    "setupTestFrameworkScriptFile": "./setup-jasmine-env.js",
    "preset": "react-native"
  }
}

setup-jasmine-env.js

var jasmineReporters = require('jasmine-reporters')
jasmine.VERBOSE = true

.babelrc

{
  "presets": [
    "react-native"
  ],
  "retainLines": true,
  "sourceMaps": true
}

Many thanks for helping!

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 22
  • Comments: 36 (1 by maintainers)

Most upvoted comments

Thanks for all the help!

My project is a library with an Examples folder. This was the problem. In this example folder i have multiple example projects with - of course - a node_modules folder in each of it.

To solve my problem i added modulePathIgnorePatterns to my jest configuration of my root library project.

package.json of my library project:

{
  "jest": {
    "modulePathIgnorePatterns": ["<rootDir>/Examples/"],
  }
}

After that i ran npm test -- --no-cache. This solved it for me.

Strangely I’ve resolved by doing:

yarn test will initially fail with Cannot find module 'setupDevtools' from 'setup.js' error. yarn test --no-cache will fail with the same error. yarn test --no-watchman will fail again. yarn test will pass.

Don’t know why but it works now. Related issue here: https://github.com/expo/jest-expo/issues/14

Appears this is still an issue I am facing right now, apparently was happening a while back but a few moments later started with this error… checked several issue/overflow questions tried many suggestion but no attempt succeeded.

I’ve had the same issue on macOS. Tried clearing all npm/yarn caches & node_modules, but I would still get the same error. Tried a npm test -- --no-cache, but still no dice (possibly because of a lerna setup where --no-cache wasnt reaching jest for some of the packages).

The only thing that would fix it was a rm -rf $TMPDIR/jest_dx.

In our case, it was related to a custom watchman config. You can check if it’s the case for you with jest --no-watchman

I’ve tried all of the above suggestions and I still can’t get rid of this error.

// test - src/utils/__tests__/foo.test.js
describe('Foo', () => {
  it('exists', () => {
    expect(true).toBeTruthy()
  })
})
// package.json - Jest config
  "jest": {
    "preset": "react-native",
    "roots": ["src"]
  }

If I remove one of those config options, the test suite runs fine. But if they are both present, I get:

 ● Test suite failed to run

    Cannot find module 'setupDevtools' from 'setup.js'
      
      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
      at Object.<anonymous> (node_modules/react-native/jest/setup.js:30:1)

Running npm test -- --no-cache made it for me

I just encountered this error on macOS. I just had to update from react-native 0.55.3 to 0.56 in this commit https://github.com/paritytech/parity-signer/pull/209/commits/961dbba30feb785470551de6cc9a8770b72bacc6

Was seeing a similar issue on our CI runs:

Test suite failed to run

    Cannot find module 'setupDevtools' from 'setup.js'
      
      at Resolver.resolveModule (../../../../../<root>/node_modules/jest-resolve/build/index.js:169:17)
      at Object.<anonymous> (node_modules/react-native/jest/setup.js:23:1)

root issue for us was that ./node_modules was symlinked to another node_modules elsewhere.

Unfortunately i still have this issue. I removed yarn.lock, removed the folder node_modules and installed the modules again.

npm run test still throws the same error:

 Test suite failed to run

    Cannot find module 'setupDevtools' from 'setup.js'
      
      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
      at Object.<anonymous> (node_modules/react-native/jest/setup.js:30:1)

The test command in my package.json looks like follows:

{
  "scripts": {
     "test": "cross-env NODE_ENV=test jest --silent --collectCoverageFrom='[\"src/**/*.{js}\"]'"
  }
}

@cpojer - you said maybe a dependency for jest was messed up. Do i have to install/update a package? The latest version of jest-cli is still 20.0.4.

@tobiasMeinhardt You have your test file in __tests__ dir? I have the same issue but if i move the test file in to __tests__ directory, it works.

@peterdev6 we were seeing this issue only on our CI, where we “cache” our node_modules and then before running npm test we would ln the ./node_modules to that cached directory. My guess is that there’s a hardcoded path to load setupDevtools, or something similar, which doesn’t like the symbolic link. In our case, switching to just mving or cping the cached directory to a local reference worked.

Hope it helps.