reactjs-找不到模块:'redux'

我已经使用package.json cli创建了一个新的react应用程序。然后我使用npm install --save react-redux添加了'react-redux'库。

package.json中,我有:

"react-redux": "^4.4.5"

不幸的是,该应用程序无法编译,并且抱怨:

Error in ./~/react-redux/lib/utils/wrapActionCreators.js
Module not found: 'redux' in C:\Users\Salman\Desktop\Courses\Internship\React\Youtube-Front-End\node_modules\react-redux\lib\utils

 @ ./~/react-redux/lib/utils/wrapActionCreators.js 6:13-29

我不知道这是什么意思?

这是完整的容器:

import React,{Component} from 'react';
import {connect} from 'react-redux';

class BookList extends Component{
  renderList(){
        return this.props.books.map((book)=>{
          <li key={book.title} >{book.title}</li>
        });
    }

  render(){

    return(
      <div>
        <ul>
          {this.renderList()}
        </ul>
      </div>
    );
  }
}

function mapStateToProps(state){
  return{
    books:state.books
  };
}

export default connect(mapStateToProps)(BookList);

这是完整的package.json

{
  "name": "Youtube-Front-End",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "react-scripts": "0.6.1",
    "webpack": "^1.13.2"
  },
  "dependencies": {
    "react": "^15.3.2",
    "react-dom": "^15.3.2",
    "react-redux": "^4.4.5",
    "youtube-api-search": "0.0.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}
Salman Lashkarara asked 2019-10-06T18:24:06Z
2个解决方案
133 votes

您需要安装react-redux但也要安装redux库。

npm install --save redux
Borjante answered 2019-10-06T18:24:18Z
5 votes

react-redux内部使用Action, ActionCreator, AnyAction, Dispatch, Store这些接口形成redux封装。

你打的那一刻

export default connect(mapStateToProps,mapDispatchToProps)(App);

react-redux尝试利用redux软件包中的所有这些接口。 目前尚不存在。

因此,您可能必须同时安装react-redux软件包和redux软件包,因为两者都具有依赖性。

 npm install --save redux react-redux
Amruth LS answered 2019-10-06T18:25:03Z
translate from https://stackoverflow.com:/questions/40082477/module-not-found-redux