expo-cli icon indicating copy to clipboard operation
expo-cli copied to clipboard

@type/react not install by default

Open ELBEQQAL94 opened this issue 2 years ago • 16 comments

Summary

I create a template react native using:

expo init AwesomeApp

The issue is @type/react is not installed by default.

Environment

expo-env-info 1.0.2 environment info: System: OS: Linux 5.13 Ubuntu 20.04.4 LTS (Focal Fossa) Shell: 5.0.17 - /bin/bash Binaries: Node: 16.0.0 - ~/.nvm/versions/node/v16.0.0/bin/node Yarn: 1.22.18 - /usr/bin/yarn npm: 7.10.0 - ~/.nvm/versions/node/v16.0.0/bin/npm npmPackages: expo: ~44.0.0 => 44.0.6 react: 17.0.1 => 17.0.1 react-dom: 17.0.1 => 17.0.1 react-native: 0.64.3 => 0.64.3 react-native-web: 0.17.1 => 0.17.1 npmGlobalPackages: expo-cli: 5.3.2 Expo Workflow: managed

Please specify your device/emulator/simulator platform, model and version

Galaxy A4

Error output

'Stack.Navigator' cannot be used as a JSX component.

Reproducible demo or steps to reproduce from a blank project

1 - run expo init AwesomeApp 2 - choose typescript template with navigation 3 - Go to navigation file and check Stack.Navigator issue

ELBEQQAL94 avatar Apr 24 '22 23:04 ELBEQQAL94

I have the same issue this week,

I have @types/[email protected] install and have this error

And when I force upgrade the version of the package to 18.0.8 all error dissapear but I can't start my app

expo start ? It looks like you're trying to use TypeScript but don't have the required dependencies installed. Would you like to install @types/react? › (Y/n)

And if I press yes, 17.0.21 appear and all error as well

Bagra67 avatar May 06 '22 10:05 Bagra67

Yeah I have the same issue

AslamJM avatar May 12 '22 14:05 AslamJM

Same issue for me too, existing project after finishing re-installing, and I have @type/react in node_modules, expo prompts: 'It looks like you're trying to use TypeScript but don't have the required dependencies installed, Would you like to install @types/react? ".

YangfanZhang avatar May 13 '22 02:05 YangfanZhang

The same issue on my end as well. I've tried to update @types/react up to the 18th version thru expo cli. It didn't work, expo forcing 17th version installation. If you'll try to update it manually - "It looks like you're trying to use TypeScript but don't have the required dependencies installed. Would you like to install @types/react? › (Y/n)" will appear.

proffesor888 avatar May 14 '22 10:05 proffesor888

Same error... various componentes with error 'nameOfComponent cannot be used as a JSX component.', but when I update @types/react to rev 18.0.8 the errors disappear, but the Expo does not recognize the @types/react and does not let me start the project, requiring the @types/react rev 17.0.21. I did update the Expo SDK to 45 with expo update, but the problem persists.

EDIT: I solved adding "resolutions": { "@types/react": "~17.0.21" }, in package.json, and runing 'yarn install' again.

va-p avatar May 19 '22 15:05 va-p

In our case the types (eg. @types/react, @types/react-dom) got updated to v18 by accident, when react-native was 0.64.3 which includes React v17. Switched to the below, no more JSX component type errors and expo is able to start metro again.

    "react": "17.0.1",
    "react-dom": "17.0.1",
    "react-native": "0.64.3",
    // devDependencies
    "@types/react": "^17.0.21",
    "@types/react-dom": "^17.0.17",
    "@types/react-native": "^0.64.3",

edwinckc avatar May 20 '22 14:05 edwinckc

The solution from @va-p seems to be a great workaround until this issue is fixed. I ran into the exact same issue.

wcandillon avatar May 27 '22 18:05 wcandillon

Just a note on @va-p's solution, I also had to rm -rf node_modules/ before running yarn install (I think to clear out some nested node_modules/.../node_modules/@types/react/ dependencies that were still using the non-resolutions version of @types/react) in order to get yarn tsc passing

helixbass avatar Jun 05 '22 12:06 helixbass

I still have the same problem, I did everything the previous posts proposed.

natancs avatar Jun 06 '22 13:06 natancs

I ran this command and it was fixed yarn remove @types/react

victorumesiobi avatar Jul 27 '22 22:07 victorumesiobi

i had the same problem and i solved updating to latest expo-cli version npm install -g expo-cli

alissonbovenzo avatar Jul 28 '22 03:07 alissonbovenzo

@alissonbovenzo solution worked. if you prefer yarn just do yarn global add expo-cli

davichaves avatar Jul 28 '22 03:07 davichaves

For me, a combination of these proposed solutions worked.

  1. update to latest expo cli as mentioned above
  2. Remove the node_modules folder as well as package-lock.json and/or yarn.lock as mentioned above
  3. yarn install
  4. expo doctor --fix-dependencies

kkmehta03 avatar Jul 28 '22 10:07 kkmehta03

Updating my expo version , deleting the node_modules folder and running yarn install after that fixed the issue for me

ezratechdev avatar Jul 29 '22 20:07 ezratechdev

@alissonbovenzo solution worked. if you prefer yarn just do yarn global add expo-cli

tks man. It worked here thnx

bruno3du avatar Jul 30 '22 23:07 bruno3du

Updating expo-cli to the latest just causes my project to no longer start properly. I have a catch 22

Sintry1 avatar Aug 16 '22 10:08 Sintry1

  1. Iirc this was fixed recently in the versioned Expo CLI (npx expo) by performing a more in-depth check of the package versions.
  2. You can disable the TypeScript check with EXPO_NO_TYPESCRIPT_SETUP=1 https://docs.expo.dev/guides/typescript/#base-configuration

If you encounter this issue in the future, please open an issue on expo/expo.

EvanBacon avatar Oct 27 '22 22:10 EvanBacon