react-native - 无法从 'react-dom' 找到模块 'mobxreact.cjs

运行 npm run test 命令时出现错误。

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

> driverApp@0.0.1 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! driverApp@0.0.1 test: `jest`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the driverApp@0.0.1 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

这是我的测试App-test.tsx文件

/**
 * @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 />);
});

我找到了解决问题的信息,但对我没有帮助。

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

package.json 文件中的jest 配置

    "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"
        ]
    }

为什么我的测试没有通过?

最佳答案

我只是简单地将 react-dom 添加到我的开发依赖项中:

yarn add react-dom --dev

关于react-native - 无法从 'react-dom' 找到模块 'mobxreact.cjs.development.js',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60428975/

相关文章:

java - openapi generator maven plugin可空属性问题

cassandra - JanusGraph 错误 : "Could not find type f

google-cloud-platform - 使用 GCP AutoML 进行自定义实体提取的预测

javascript - 禁用移动浏览器滑动返回行为?

swift - 使用 Storyboard将 Collection View 布局设置为组合布局

c# - 在 Visual Studio 2019 中添加带有 css 类的 div 的键盘快捷方式

reactjs - Auth0 并使用react,将用户重定向到注册页面

oracle - JDBC 故障转移连接字符串

python - pandas 将嵌套字典转换为 mutiIndex 行和列

mysql - 无法在 AWS-mysql 中创建表并抛出错误代码 1044。拒绝用户 'user1