21

I am receiving an error while trying to use Typescript with my existing expo project.

While following the docs, I created a tsconfig.json file in the project root.

When running expo start, I am prompted to install the typescript dependencies. However, after these are successfully installed (tick message appears in console: √ Installed typescript@~4.3.5, @types/react@~17.0.21, @types/react-native@~0.67.6), I receive the following error:

It looks like you're trying to use TypeScript but don't have the required dependencies installed.

Please install @types/react by running:

yarn add --dev @types/react@~17.0.21

If you're not using TypeScript, please remove the TypeScript files from your project and delete the tsconfig.json.

error Command failed with exit code 1.

After following the instructions and running the yarn add .... command, I keep seeing the same error message.

I have tried deleting the node_modules folder and package-lock.json file to no avail. I have also tried following this answer. Any assistance would be appreciated, thank you.

RossB
  • 329
  • 1
  • 2
  • 4
  • I'm having the exact same issue. Have you perhaps figured out a way to resolve this issue? – Reez0 Aug 02 '22 at 12:23
  • So, running ```yarn add expo-cli``` may fix the error, however this results in the local development server not starting up. I can start the server by running ```expo start``` directly, rather than using ```yarn start```, but the error is back again! Very odd. – RossB Aug 03 '22 at 21:24

7 Answers7

14

Just re-install expo-cli npm install -g expo-cli.

Josué Mendonça
  • 460
  • 4
  • 11
12

Seems to be a bug. It works if I install @types/react on the specific version that Expo requests (17.0.21).

yarn add --dev @types/react@17.0.21
tiagodws
  • 1,345
  • 13
  • 20
  • Apart some mismatch with old expo api with typescript could be then the issue? – Carmine Tambascia Aug 30 '22 at 17:44
  • Wow, this was true for me too. I'm using Next.js (not Expo), and originally my repo had `"@types/react": "^17.0.38",` and everything worked fine. Then suddenly my `yarn dev` wouldn't work even though I didn't have any changes to my code. I must have at some point let yarn install a newer version of @types/react and then reverted it, and I'd forgotten to delete the folder(s) from `node_modules` and do `yarn install` again. – Ryan Oct 02 '22 at 13:59
  • Wow, this is so bizarre. It just happened for me again on another computer. To solve it, I ran `git checkout yarn.lock && rm -rf node_modules/@types/react && yarn add -D @types/react@17.0.38 && yarn install`. Basically this removed the ^ from `"@types/react": "^17.0.38"`. – Ryan Oct 04 '22 at 13:14
3

I don't know which of the following worked, but I ran the following commands and the problem went away.

  • sudo npm install -g expo-cli

  • sudo npm install -g @types/react

  • sudo npm install -g @types/react-native

  • sudo npm install -g typescript

Reez0
  • 2,512
  • 2
  • 17
  • 39
2
yarn add expo-cli

solved for me.

1

I had the same issue. I resolved it by :

1- delete the node_modules.

2- update expo to the latest version using npm i -g expo-cli

hope this will help someone

0

if you installed @types/react remove that from your dev dependencies

0

I solved it running YARN_CHECKSUM_BEHAVIOR=update yarn