错误:无法解析模块react-redux / native

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

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

的package.json:

{“name”:“Testing”,“version”:“0.0.1”,“private”:true,“scripts”:{“start”:“node node_modules / react-native / local-cli / cli.js start“,”test“:”jest“},”dependencies“:{”react“:”15.4.1“,”react-native“:”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“,”jest“:”18.1.0“,”react-test-renderer“:”15.4.1“},”jest“:{”preset“:”react-native“} }

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);

请协助解决问题 .

回答(1)

3 years ago

index.js of react-redux开始,您可以直接 react-redux 导出 Provider .

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

您还可以查看here中的示例 .