react-native-vector-icons: type 'typeof Icon' is not a valid JSX element type

Environment

This issue happens in code. here’s an screenshot: image

image

Description

After upgrading RN to version 0.72.5 this issue happened. here’s my package.json:

{
 ...  
  "dependencies": {
    "react": "18.2.0",
    "react-native": "0.72.5",
    "react-native-svg": "^13.14.0",
    "react-native-vector-icons": "^10.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.23.0",
    "@babel/preset-env": "^7.22.20",
    "@babel/runtime": "^7.23.1",
    "@react-native-community/eslint-config": "^3.2.0",
    "@react-native/metro-config": "^0.73.1",
    "@tsconfig/react-native": "^3.0.2",
    "@types/jest": "^29.5.5",
    "@types/react-test-renderer": "^18.0.3",
    "babel-jest": "^29.7.0",
    "babel-plugin-module-resolver": "^5.0.0",
    "eslint": "^8.50.0",
    "eslint-plugin-unused-imports": "^3.0.0",
    "jest": "^29.7.0",
    "metro-react-native-babel-preset": "^0.77.0",
    "prettier": "^3.0.3",
    "react-native-svg-transformer": "^1.0.0",
    "react-test-renderer": "18.2.0",
    "typescript": "^5.2.2",
    "@types/react": "^18.2.28",
    "@types/react-native": "^0.72.3",
    "@types/react-native-vector-icons": "^6.4.15"
  },
...   
}

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 9
  • Comments: 15 (1 by maintainers)

Most upvoted comments

In my case yarn already executes yarn dedupe automatically so that didn’t solve the problem.

What solved the problem for me was forcing the resolution in my package.json like so:

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

The only workaround I found was to do this: Replace this

import IonIcon from 'react-native-vector-icons/IonIcons';

With this

const IonIcon = require('react-native-vector-icons/IonIcons').default as React.ElementType;

I tried to remove node_module, yarn.lock. then update “@types/react”: “18.2.39”, “@types/react-native”: “^0.72.7” and it work

This works like a charm ✨❤️

I tried to remove node_module, yarn.lock. then update “@types/react”: “18.2.39”, “@types/react-native”: “^0.72.7” and it work

I also have the same type error.

I fixed it with:

import _IonIcon from 'react-native-vector-icons/Ionicons';

const IonIcon = _IonIcon as React.ElementType;

This is a mismatch between various @types/react versions installed by various packages.

I’m using yarn 3 and I was able to fix it by running yarn dedupe