gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 07:12:20 25 4
gpt4 key购买 nike

运行 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com