Typescript cannot find redux

前端 未结 4 1782
野性不改
野性不改 2020-12-25 12:06

I am getting the following error:

node_modules/@types/react-redux/index.d.ts(8,24): error TS2307: Cannot find module \'redux\'.

despite hav

相关标签:
4条回答
  • 2020-12-25 12:11

    If you encounter the same issue with the following react version "^16.8.6" verify if the npm redux package

    Package.json

    "dependencies": {
        "@types/jest": "24.0.13",
        "@types/node": "12.0.3",
        "@types/react": "16.8.19",
        "@types/react-dom": "16.8.4",
        "react": "^16.8.6",
        "react-dom": "^16.8.6",
        "react-redux": "^7.0.3",
        "react-scripts": "3.0.1",
        "redux": "^4.0.1",
        "typesafe-actions": "^4.4.0",
        "typescript": "3.5.1"
      },
    

    if not installed just do npm install redux no need for npm i @types/reduxas Redux package provides its own type definitions, so you don't need @types/redux installed!

    0 讨论(0)
  • 2020-12-25 12:13

    I reverted to @types/redux@3.6.31 and that resolved the problem. This version includes the index.d.ts file for redux. There might be a problem with the TypeScript compiler not looking for the index.d.ts file in the normal node_modules/redux directory, but only under node_module/@types.

    0 讨论(0)
  • 2020-12-25 12:19

    I experienced the same problem on a react-native project. This fix worked for me:

    You have to add "moduleResolution": "node" to the compiler options in order to include type definitions linked in package.json files.

    Documentation here https://www.typescriptlang.org/docs/handbook/module-resolution.html

    0 讨论(0)
  • 2020-12-25 12:33

    I already had moduleResolution: 'node' and @types/redux was deleted. But when I deleted node_modules and reinstalled, the problem went away. :shrug.

    0 讨论(0)
提交回复
热议问题