rt2zz / redux-persist

persist and rehydrate a redux store
MIT License
12.91k stars 862 forks source link

'PersistGate' cannot be used as a JSX component. #1375

Open ajnozari opened 2 years ago

ajnozari commented 2 years ago

This is a rather new issues that's suddenly popped up.

Previously working config now reports PersistGate is not a valid JSX component?

AndrePereiraSF commented 2 years ago

Same issue happening to me today

ajnozari commented 2 years ago

If I'm understanding this issue, it's due to an update to React to v18.

React-redux uses "*" for the type on @types/react

A workaround add :

"resolutions": {
    "@types/react": "17.0.43"
}

to your package.json

fregayeg commented 2 years ago

try this:

"devDependencies": {
    "@types/react": "18.0.0"
  },
dohuuhuy commented 2 years ago

"@types/react": "17.0.43" tried but it doesn't work

dohuuhuy commented 2 years ago

image

Has anyone encountered this error?

avasuro commented 2 years ago

Solution if you are using React v17 with Yarn and/or npm 18.3.0+

For those who are using Yarn, as suggested by @ajnozari add the following to your package.json:

"resolutions": {
  "@types/react": "17.0.44"
}

For those who are using npm version 8.3.0+ add the following to your package.json, remove node_modules and do npm install again:

"overrides": {
  "@types/react": "17.0.44"
}

Both that options will force yarn or npm to install and use this specific version of react types for all installed packages. Note: version 17.0.44 is not mandatory, use any version you want, it just should be consistent in all places in your package.json. So in my case my package.json looks like this:

"devDependencies": {
  "@types/react": "17.0.44"
},
"overrides": {
  "@types/react": "17.0.44"
},
"resolutions": {
  "@types/react": "17.0.44"
}
Ryan-cyi commented 2 years ago

Same issue happening to me today

fawaz-ahmed commented 2 years ago

This worked for me, thanks @avasuro. Also I updated react-dom version :

"devDependencies": {
  "@types/react": "17.0.44",
  "@types/react-dom": "17.0.17",
},
"overrides": {
  "@types/react": "17.0.44"
},
"resolutions": {
  "@types/react": "17.0.44"
}
duranmla commented 1 year ago

If I'm understanding this issue, it's due to an update to React to v18.

React-redux uses "*" for the type on @types/react

A workaround add :

"resolutions": {
    "@types/react": "17.0.43"
}

to your package.json

This won't affect all your dependencies and make them resolve the React types from a version 17.0.43 when we actually want to update to React 18?

duranmla commented 1 year ago

It seems more accurate to update react and react-dom types https://stackoverflow.com/a/71848896/1422380