Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I get an error when running the npm run test command.

user@user-ps:~/documents/driver-app$ npm run test

> [email protected] test /home/user/documents/driver-app
> jest

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

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

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

    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:259:17)
      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:        9.031s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `jest`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2020-02-27T07_58_19_815Z-debug.log

It's my test App-test.tsx file

/**
 * @format
 */

import 'react-native';
import React from 'react';
import { App } from './../App';

// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';

it('renders correctly', () => {
    renderer.create(<App />);
});

I found information to solve my problem, but it didn’t help me.

https://github.com/mobxjs/mobx-react/issues/764#issuecomment-524507782

My jest configuration in package.json file

    "jest": {
        "preset": "react-native",
        "transformIgnorePatterns": [
            "node_modules/(?!(jest-)?react-native|@?react-navigation|@?react-native-community)"
        ],
        "setupFiles": [
            "./node_modules/react-native-gesture-handler/jestSetup.js"
        ],
        "moduleFileExtensions": [
            "ts",
            "tsx",
            "js",
            "jsx",
            "json",
            "node"
        ]
    }

Why don't my test pass?

like image 922
MegaRoks Avatar asked Jul 09 '26 19:07

MegaRoks


1 Answers

I just simple add react-dom to my dev dependencies:

yarn add react-dom --dev
like image 122
Nguyễn Anh Tuấn Avatar answered Jul 11 '26 20:07

Nguyễn Anh Tuấn