简体   繁体   English

找不到模块:无法解决“ redux-thunk ”错误我已经尝试了解决方案,但没有发生。解决方案是什么?

[英]Module not found: can't resolve' redux-thunk ' error I have tried the solutions but it does not happen.What is the solution?

I tried all the commands for redux but it doesn't work:how do you think the solution is.我尝试了 redux 的所有命令,但它不起作用:您认为解决方案如何。 These are the commands I tried这些是我试过的命令

yarn add react-redux
yarn add reduxjs / Redux-thunk#master
npm install --save Redux react-redux
npm install redux -- save
npm i redux -- save
yarn add redux-thunk

index.jsx索引.jsx

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import {createStore, applyMiddleware,compose} from 'redux';
import rootReducer from './store/reducers/rootReducer';
import {Provider} from 'react-redux';
import thunk from 'redux-thunk';
import {reduxFirestore,getFirestore} from 'redux-firestore'
import {reactReduxFirebase,getFirebase} from 'react-redux-firebase'
import fbConfig from './config/fbConfig';


const store=createStore(rootReducer,
    compose(
        applyMiddleware(thunk.withExtraArgument({getFirebase,getFirestore})),
        reduxFirestore(fbConfig),
        reactReduxFirebase(fbConfig)
    ));


ReactDOM.render(<Provider store={store}><App /></Provider>, document.getElementById('root'));

package.json包.json

{
  "name": "omaga-yazilim",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^npm i --save react-router4.2.4",
    "@testing-library/react": "^9.4.0",
    "@testing-library/user-event": "^7.2.1",
    "firebase": "^7.8.1",
    "jest-leak-detector": "^25.1.0",
    "moment": "^2.22.2",
    "react": "^16.6.3",
    "react-dom": "^16.6.3",
    "react-redux": "^7.1.3",
    "react-redux-firebase": "^3.1.1",
    "react-router": "^4.4.0-beta.8",
    "react-router-dom": "^4.4.0-beta.6",
    "react-scripts": "^2.1.1",
    "redux": "^4.0.5",
    "redux-firestore": "^0.12.0",
    "redux-thunk": "reduxjs/redux-thunk#master",
    "start": "webpack-dev-server --mode development"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

I faced the same problem but I run the command line:我遇到了同样的问题,但我运行了命令行:

npm install --save redux-thunk npm install --save redux-thunk

The simplest solution is to use our new official Redux Toolkit package .最简单的解决方案是使用我们新的官方 Redux Toolkit 包 The configureStore function will automatically set up the store correctly, including adding the thunk middleware by default. configureStore函数会自动正确设置存储,包括默认添加 thunk 中间件。 Given that you're trying to use React-Redux-Firebase, you can do that by using the getDefaultMiddleware API :鉴于您正在尝试使用 React-Redux-Firebase,您可以使用getDefaultMiddleware API来做到这一点:

const store = configureStore({
    reducer: rootReducer,
    middleware: [...getDefaultMiddleware({
        thunk: {
            extraArgument: {getFirebase,getFirestore}
        }
    })],
    enhancers: [reduxFirestore(fbConfig), reactReduxFirebase(fbConfig)]
})

I had a similar issue with this and this is how i resolved it:我有一个类似的问题,这就是我解决它的方法:

Stop the server:Ctrl C in terminal.停止服务器:终端中的Ctrl C。

Open package.json and manually add:打开 package.json 并手动添加:

"redux-thunk": "^2.3.0",

then in the terminal cd into the project and install redux thunk:然后在终端 cd 进入项目并安装 redux thunk:

yarn add redux-thunk 

restart the server:重启服务器:

yarn start

More details about redux thunk can be found on this link:可以在此链接上找到有关 redux thunk 的更多详细信息:

ReduxThunk-Github ReduxThunk-Github

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM