When I used typescript to create my react project, I introduced Redux error reporting, which indicated that I could not find it, but I had to install all the dependencies.
Here's my 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"
}
}
Here's my store
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)
))
Unfortunately, the app doesn't compile and it complains with:
./node_modules/[email protected]@react-redux/es/connect/mapDispatchToProps.js
Module not found: Can't resolve 'redux' in '~/node_modules/[email protected]@react-redux/es/connect'
What should I do is right. Please help me, thanks.
To solve the error "Module not found: Error: Can't resolve 'redux'", make sure to install the redux package by opening your terminal in your project's root directory and running the command npm install redux react-redux and restart your development server.
The redux module should NOT be globally installed or be in your project's devDependencies, it should be in the dependencies object in your package.json file. You can try to manually add the lines and re-run npm install.
To solve the error "Module not found: Error: Can't resolve 'react/jsx-runtime'", make sure to update the react package by opening your terminal in your project's root directory and running the command npm install react@latest react-dom@latest and restart your dev server.
You need to install react-redux but also a redux library, both are kind of dependent on each other. Don't forget to import it. Show activity on this post. Show activity on this post. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. Provide details and share your research! But avoid …
Try to install both redux and react-redux at same time:
npm install --save redux react-redux
This worked for me
npm install --save redux react-redux
For people that might come across this in the future, I came across the same issue.
I was calling connect(mapStateToProps, null)(Component)
. All I had to do was actually pass in a proper mapDispatchToProps
argument and it solved the problem.
It had nothing to do with redux not being properly installed.
--save
means that dependency install as local dependency, that means related for that particular project.
npm install redux -g
in here redux install as global dependency
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With