【问题标题】:Error: Unable to resolve module react-redux/native错误:无法解析模块 react-redux/native
【发布时间】:2017-06-06 21:39:31
【问题描述】:

我正在使用 Redux 尝试我的第一个 react-native 应用程序,并在设备上运行应用程序时收到以下错误消息,

“UnableToResolveError:无法从 C:\project\Testing\index.android.js 解析模块 react-redux/native: 模块映射或这些目录中不存在模块:C:\project\Testing\node_modules\react-redux"

package.json:

{
"名称": "测试",
“版本”:“0.0.1”,
“私人”:是的,
“脚本”:{
"开始": "节点 node_modules/react-native/local-cli/cli.js 开始",
“测试”:“开玩笑”
},
“依赖”:{
“反应”:“15.4.1”,
“反应原生”:“0.40.0”,
"react-redux": "^5.0.2",
"redux": "^3.6.0",
“redux-thunk”:“^2.2.0”
},
“devDependencies”:{
"babel-jest": "18.0.0",
"babel-preset-react-native": "1.9.1",
“笑话”:“18.1.0”,
“反应测试渲染器”:“15.4.1”
},
“笑话”:{
“预设”:“反应原生”
}
}

index.android.js:

import React, { AppRegistry } from 'react-native';
import { Provider } from 'react-redux/native';
import App from './src/containers/App';
import configStore from './src/stores/configStore';
const store = configStore();
var TestingApp = React.createClass({
  render () {
    return (
      ...
    );
  }
});
AppRegistry.registerComponent('TestingApp', () => TestingApp);

请协助解决问题。

【问题讨论】:

    标签: reactjs react-native react-redux


    【解决方案1】:

    index.js of react-redux可以得知Provider是由react-redux直接导出的。

    所以你应该使用import { Provider } from 'react-redux' 而不是import { Provider } from 'react-redux/native'

    您也可以查看here 中的示例。

    【讨论】:

    • 能否请您为您的答案添加更多上下文。仅代码的答案很难理解。如果您可以在帖子中添加更多信息,这将对提问者和未来的读者都有帮助。
    猜你喜欢
    • 1970-01-01
    • 2019-08-09
    • 2019-07-06
    • 1970-01-01
    • 2019-08-16
    • 2022-12-12
    • 2022-07-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多