无法将打字稿与 expo 一起使用 - "It looks like you're trying to use TypeScript but don't have the required dep



我在尝试将Typescript用于现有的expo项目时收到错误。

在遵循文档的同时,我在项目根目录中创建了一个tsconfig.json文件。

运行expo start时,系统会提示我安装typescript依赖项。然而,在成功安装后(控制台中出现勾选消息:√ Installed typescript@~4.3.5, @types/react@~17.0.21, @types/react-native@~0.67.6(,我收到以下错误:

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.

按照说明并运行yarn add ....命令后,我一直看到相同的错误消息。

我尝试删除node_modules文件夹和package-lock.json文件,但没有成功。我也试着遵循这个答案。如有任何帮助,我们将不胜感激,谢谢。

只需重新安装expo-clinpm install -g expo-cli

似乎是个bug。如果我在Expo请求的特定版本(17.0.21(上安装@types/react,它就会工作。

yarn add --dev @types/react@17.0.21

我不知道下面哪一个有效,但我运行了下面的命令,问题就解决了。

  • sudo npm install -g expo-cli

  • sudo npm install -g @types/react

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

  • sudo npm install -g typescript

yarn add expo-cli

为我解决。

我遇到了同样的问题。我通过解决了这个问题

1-删除node_modules。

2-使用npm i-g expo-cli 将expo更新到最新版本

希望这能帮助

如果您安装了@types/react,请将其从开发依赖项中删除

我运行YARN_CHECKSUM_BEHAVIOR=update yarn解决了这个问题

相关内容

最新更新