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

时间:2019-03-16 17:48:51

标签: reactjs typescript redux

当我使用打字稿来创建我的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'

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

5 个答案:

答案 0 :(得分:1)

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

  

npm install-保存redux react-redux

答案 1 :(得分:1)

这对我有用

npm install --save redux react-redux

答案 2 :(得分:1)

--save意味着依赖项将作为本地依赖项安装,这意味着与该特定项目相关。

npm install redux -g在此处作为全局依赖项进行redux安装

答案 3 :(得分:1)

这对我有用

npm install --save redux react-redux

答案 4 :(得分:0)

对于将来可能遇到此问题的人们,我遇到了同样的问题。

我正在打#Gets the service principal (missing in problem subscription) get-azAdServicePrincipal -DisplayNameBeginsWith 'Microsoft.Azure.Websites' #Sets the keyvault access policy for the built in service principal set-azKeyVaultAccessPolicy -VaultName keyVaultName -ServicePrincipalName "abfa0a7c-a6b6-4736-8310-5855508787cd" -PermissionsToSecrets get 。我所要做的实际上只是传递一个适当的connect(mapStateToProps, null)(Component)参数,它解决了问题。

与redux安装不正确无关。