未找到模块:无法解析 node_modules 中的“redux”

新手上路,请多包涵

我在使用 typescript 创建我的 react 项目时,引入了 Redux 报错,提示找不到,但必须安装所有依赖项。

这是我的 package.json

 {
  "name": "react-test",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@types/jest": "^24.0.11",
    "@types/node": "^11.11.3",
    "@types/react": "^16.8.8",
    "@types/react-dom": "^16.8.2",
    "@types/react-redux": "^7.0.3",
    "@types/react-router-dom": "^4.3.1",
    "axios": "^0.18.0",
    "react": "^16.8.4",
    "react-dom": "^16.8.4",
    "react-redux": "^6.0.1",
    "react-router-dom": "^4.4.0",
    "react-scripts": "2.1.8",
    "redux": "^4.0.1",
    "redux-devtools-extension": "^2.13.8",
    "redux-thunk": "^2.3.0",
    "typescript": "^3.3.3333"
  },
  "scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "babel-plugin-import": "^1.11.0",
    "customize-cra": "^0.2.12",
    "node-sass": "^4.11.0",
    "react-app-rewired": "^2.1.1"
  }
}

这是我的商店

import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
import { composeWithDevTools } from 'redux-devtools-extension'

import reducer from './reducer'

const store = createStore(reducer, composeWithDevTools(
   applyMiddleware(thunk)
))

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

 ./node_modules/_react-redux@6.0.1@react-redux/es/connect/mapDispatchToProps.js
Module not found: Can't resolve 'redux' in '~/node_modules/_react-redux@6.0.1@react-redux/es/connect'

我该怎么做才是对的。请帮助我,谢谢。

原文由 ming xiao 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.1k
2 个回答

尝试同时安装 redux 和 react-redux:

npm install –save redux react-redux

原文由 James Delaney 发布,翻译遵循 CC BY-SA 4.0 许可协议

这对我有用

npm install –save redux 反应-redux

原文由 amit sharma 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进