Skip to content
This repository was archived by the owner on Dec 31, 2020. It is now read-only.

React Native + Jest: Cannot find module 'react-dom' from 'mobxreact.cjs.development.js' #844

Closed
jayshah123 opened this issue Mar 9, 2020 · 4 comments
Labels

Comments

@jayshah123
Copy link

Having a fairly barebones react-native + mobx setup here (https://github.com/jayshah123/mobx-jest-test-error)
Running npm test asks forreact-dom dependency.

Intended outcome

Jest test should run as expected

Actual outcome

Test fails saying: Cannot find module 'react-dom' from 'mobxreact.cjs.development.js'

Full error:

bash-3.2$ npm test

> [email protected] test /Users/jay.shah/Documents/sampleapps/JestMobxChecker
> jest

 FAIL  __tests__/App-test.js
  ● Test suite failed to run

    Cannot find module 'react-dom' from 'mobxreact.cjs.development.js'

    However, Jest was able to find:
        './ColorComponent.js'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'json', 'jsx', 'ts', 'tsx', 'node'].

    See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

    However, Jest was able to find:
        '../App.js'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'json', 'jsx', 'ts', 'tsx', 'node'].

    See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:276:11)
      at Object.<anonymous> (node_modules/mobx-react/dist/mobxreact.cjs.development.js:10:16)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.401s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

How to reproduce the issue

https://github.com/jayshah123/mobx-jest-test-error

  1. clone the repo
  2. npm install
  3. npm test

Versions

    "mobx": "^5.15.4",
    "mobx-react": "^6.1.8",
    "react": "16.9.0",
    "react-native": "0.61.5"
@jayshah123 jayshah123 added the bug label Mar 9, 2020
@danielkcz
Copy link
Contributor

danielkcz commented Mar 9, 2020

This will be generally solved by #787 once I get to finishing it up :)

For now, you basically have to force mobx-react in Jest config to resolve to RN bundle instead of regular CJS one.

Hm, that might not actually work because RN bundle uses ESM which Jest cannot handle afaik. Cannot think of any viable workaround for now so I guess it makes #787 fairly important now :)

@vonovak
Copy link
Contributor

vonovak commented Mar 20, 2020

@jayshah123 this PR makes the test run jayshah123/mobx-jest-test-error#1 . I didn't go any further than that though, so not sure if some more complicated tests relying on mobx will work too.)

@danielkcz
Copy link
Contributor

danielkcz commented Apr 22, 2020

Please, upgrade to mobx-react 6.2.0 and see instructions in the readme.

@lock
Copy link

lock bot commented Jun 24, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants