Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module 'setupDevtools' from 'setup.js' - Platform Windows #3822

Closed
meinto opened this issue Jun 14, 2017 · 36 comments
Closed

Cannot find module 'setupDevtools' from 'setup.js' - Platform Windows #3822

meinto opened this issue Jun 14, 2017 · 36 comments

Comments

@meinto
Copy link

meinto commented Jun 14, 2017

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!

@tuanmai
Copy link

tuanmai commented Jun 15, 2017

@tobiasMeinhardt Hey, we encountered the same issue with you. Our solution is
rm yarn.lock && rm -rf node_modules && yarn. Seems that there is a problem with the yarn.lock file

@cpojer
Copy link
Member

cpojer commented Jun 15, 2017

I think that was some dependency that I published either for Jest or Metro that was messed up, now it should be resolved.

@cpojer cpojer closed this as completed Jun 15, 2017
@blackxored
Copy link

I'm having the same issue:

yarn list v0.24.6
├─ [email protected]
├─ [email protected]
└─ [email protected]
✨  Done in 1.00s.

Did clean node_modules and yarn.lock.

@brobiden
Copy link

Still having this issue as well

@meinto
Copy link
Author

meinto commented Jun 15, 2017

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.

@khanghoang
Copy link

@tobiasMeinhardt can you create a fresh RN project and try to run jest on it. I know it's weird but let try it, if it works then maybe you need to clean your project.
In my case, I need to clean everything to make it work again.

@meinto
Copy link
Author

meinto commented Jun 16, 2017

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.

@zheng-liu-seattle
Copy link

i am also having this issue, on mac, tried to clean node_modules, but still see it.

@phillbaker
Copy link

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.

@ancyrweb
Copy link

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

@peterleilei86
Copy link

Having the same issue!
OS: Mac OS,
jest config:

"jest": {
    "preset": "react-native",
    "transform": {
      "^.+\\.js$": "<rootDir>/node_modules/babel-jest",
      ".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js",
      "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/fileTransformer.js"
    },
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js"
    ],
    "moduleNameMapper": {
      "\\.(css|less)$": "identity-obj-proxy",
      "^React$": "<rootDir>/node_modules/react"
    },
    "modulePathIgnorePatterns": [
      "<rootDir>/node_modules/react-native/Libraries/"
    ],
    "verbose": true
  }

package.js:

"dependencies": {
    ......
   "react": "16.0.0-alpha.13",
   "react-dom": "16.0.0-alpha.13",
   "react-native": "0.45.1"
},
"devDependencies": {
    "@types/jest": "^20.0.2",
    "babel-cli": "^6.2.0",
    "babel-core": "^6.10.4",
    "babel-jest": "^20.0.3",
    "babel-preset-react-native": "^1.9.2",
    "jest": "^20.0.4",
    "jest-cli": "^20.0.4",
    "react-test-renderer": "^15.6.1",
    "regenerator-runtime": "^0.10.5",
    "ts-jest": "^20.0.6",
     #......
}

@peterleilei86
Copy link

@phillbaker Hey I am having the same issue. Can you elaborate the root issue on your case and the solution? Thanks so much

@phillbaker
Copy link

@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.

@peterorum
Copy link

I had a newer version of react-native-svg that expected a later version of react native than i'm using, so i re-installed the older version of react-native-svg for the time-being.

@sarovin
Copy link

sarovin commented Jul 12, 2017

@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.

@SupriyaKalghatgi
Copy link

This issue keeps appearing every now and then
I am frustrated with it

@sarovin
Copy link

sarovin commented Aug 8, 2017

@SupriyaKalghatgi i have this issue if i add extra options in package.json...
i have fixed with this:

"jest": {
    "preset": "jest-react-native"
  }

@SupriyaKalghatgi
Copy link

@sarovin Thats an expo app of mine
So i have included

"jest": {
    "preset": "jest-expo",
}

@ptmt
Copy link

ptmt commented Aug 8, 2017

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

@dlindahl
Copy link

dlindahl commented Sep 1, 2017

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)

@larsonjj
Copy link

larsonjj commented Sep 5, 2017

I ran into the same problem today. Was able to solve it with the following jest config within package.json:

"jest": {
    "preset": "jest-expo",
    "testPathIgnorePatterns": [
      "/node_modules/"
    ],
    "moduleFileExtensions": [
      "js",
      "jsx",
      "json"
    ],
    "moduleDirectories": [
      "packages",
      "node_modules"
    ]
  },

@trevorah
Copy link

trevorah commented Sep 6, 2017

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.

@chenasraf
Copy link

Also have the same issue:

Cannot find module 'enzyme' from 'enzyme_setup.js'
   at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:191:17)
   at Object.<anonymous> (test/enzyme_setup.js:1:108)

Here's my enzyme_setup.js:

const configure = require('enzyme').configure
const Adapter = require('enzyme-adapter-react-16')

configure({ adapter: new Adapter() })

And here's my package.json's jest section:

"jest": {
    "resolver": "jest-webpack-resolver",
    "transform": {
      "^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
    },
    "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js",
      "jsx",
      "json"
    ],
    "moduleDirectories": [
      "node_modules",
      "app"
    ],
    "moduleNameMapper": {
      "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/test/unit/__mocks__/fileMock.js",
      "\\.(css)$": "identity-obj-proxy"
    },
    "snapshotSerializers": [
      "enzyme-to-json/serializer"
    ],
    "setupFiles": [
      "<rootDir>/test/enzyme_setup"
    ],
    "verbose": true
  },
  "jestWebpackResolver": {
    "webpackConfig": "<rootDir>/webpack/webpack.common.js"
  }

I also tried with different presets and without presets, none showed any change.

@LRNZ09
Copy link

LRNZ09 commented Nov 21, 2017

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

@pintocarlos
Copy link

pintocarlos commented Dec 8, 2017

Try running jest with the flag --no-cache once and then rerunning without the flag.
That fixed it for me.

In my case, I started experiencing the setup.js error for no particular reason, given that there were no changes on source control and it was working fine on other local environments and CI.

@dwilhel1
Copy link

I had this issue as well on my OSX / Mac platform and found a solution this morning. As it turns out, Babel has documentation which specifically explains how to setup Jest when used together. In summary, here's what I did:

Install NPM Modules

npm install --save-dev babel-jest
npm install --save-dev babel-preset-env

or with one command:

npm install i -d babel-jest babel-preset-env

Create .babelrc Config File

{
  "presets": ["env"]
}

Modify package.json

{
  "scripts": {
    "test": "jest"
  },
  "jest": {
    "transform": {
      "^.+\\.jsx?$": "babel-jest"
    }
  }
}

Here is some further reading on why the env preset configuration is needed. Happy coding!

@Quadriphobs1
Copy link

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.

@marcelkalveram
Copy link

I've had this issue after an update from React Native from 0.55 to 0.56.

We're using https://github.com/infinitered/jest-preset-ignite and this PR solved the issue for us: https://github.com/infinitered/jest-preset-ignite/pull/3/files.

The diff should also work for non-ignite projects, or at least help you figure out what's needed for the 0.56 migration.

@DZuz14
Copy link

DZuz14 commented Oct 3, 2018

For anyone going absolutely insane...might be worthwhile to just give this a shot, this is all it took for me.

  "jest": {
    "preset": "./node_modules/babel-jest",
    "roots": [
      "<rootDir>/__tests__"
    ]
  }

@raven-chen
Copy link

By digging into the react-native/jest/setup.js. I found if I change

jest.mock('setupDevtools') to jest.mock('../Libraries/Core/Devtools/setupDevtools.js').

This error will be gone.

But another one Cannot find module 'InitializeCore' showed up. Changing this to jest.mock('../Libraries/Core/InitializeCore.js') resolved the error too. but another one showed up.

So it looks like something wrong with loading the modules inside ../Libararies. keep invesgitating..

@ltfschoen
Copy link

ltfschoen commented Jan 30, 2019

I just encountered this error on macOS. I just had to update from react-native 0.55.3 to 0.56 in this commit novasamatech/parity-signer@961dbba

@adrian-moisa
Copy link

Several bugfixes were needed, and I managed to get the tests running:

  • Eliminates unknown "export" token: "Unexpected token export, when import not compiled libraries"
"transformIgnorePatterns": [
    "node_modules/?!(react-router)"
],
  • Removed jsdom - no longer emulating browser environment for react native. "TypeError: Cannot set property '_eventListeners' of undefined” with jest"
  • Updated: testPathIgnorePatterns to ignore all folders except "src" so we can remove roots: ["src"] which causes: "Cannot find module 'setupDevtools' from 'setup.js'"

@willgriffiths
Copy link

willgriffiths commented Aug 30, 2019

I had accidentally added testEnvironment="node" instead of just using the "react-native" preset and removing it fixed it for me.

module.exports = {
  testEnvironment: "node", // <---- removing this 
  preset: "react-native"
};

@thymikee
Copy link
Collaborator

RN preset uses node environment so what you did is invalidating Jest cache. You can do so with a command jest --clearCache

@youngjuning
Copy link

My situation:

react-native: 0.59.10
react: 16.8.3
jest: 24.9.0
babel-jest: 24.9.0

  • remove modulePathIgnorePatterns: ['node_modules'], from jest.config.js

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests