expo-cli
expo-cli copied to clipboard
@type/react not install by default
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
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
Yeah I have the same issue
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? ".
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.
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.
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",
The solution from @va-p seems to be a great workaround until this issue is fixed. I ran into the exact same issue.
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
I still have the same problem, I did everything the previous posts proposed.
I ran this command and it was fixed yarn remove @types/react
i had the same problem and i solved updating to latest expo-cli version
npm install -g expo-cli
@alissonbovenzo solution worked. if you prefer yarn just do
yarn global add expo-cli
For me, a combination of these proposed solutions worked.
- update to latest expo cli as mentioned above
- Remove the node_modules folder as well as package-lock.json and/or yarn.lock as mentioned above
-
yarn install
-
expo doctor --fix-dependencies
Updating my expo version , deleting the node_modules folder and running yarn install after that fixed the issue for me
@alissonbovenzo solution worked. if you prefer yarn just do
yarn global add expo-cli
tks man. It worked here thnx
Updating expo-cli to the latest just causes my project to no longer start properly. I have a catch 22
- Iirc this was fixed recently in the versioned Expo CLI (
npx expo
) by performing a more in-depth check of the package versions. - 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.