无法在 expo 中使用 TypeScript - “看起来您正在尝试使用 TypeScript,但没有安装所需的依赖项”

Ros*_*ssB 21 javascript dependencies typescript react-native expo

我在尝试在现有的博览会项目中使用 Typescript 时收到错误。

\n

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

\n

运行时expo start,系统会提示我安装打字稿依赖项。但是,成功安装这些后(控制台中出现勾选消息:)\xe2\x88\x9a Installed typescript@~4.3.5, @types/react@~17.0.21, @types/react-native@~0.67.6,我收到以下错误:

\n

\r\n
\r\n
It looks like you\'re trying to use TypeScript but don\'t have the required dependencies installed.\n\nPlease install @types/react by running:\n\nyarn add --dev @types/react@~17.0.21\n\nIf you\'re not using TypeScript, please remove the TypeScript files from your project and delete the tsconfig.json.\n\nerror Command failed with exit code 1.
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n

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

\n

我尝试删除node_modules文件夹和package-lock.json文件但无济于事。我也尝试遵循这个答案。\n任何帮助将不胜感激,谢谢。

\n

Jos*_*nça 14

只需重新安装 expo-cli 即可npm install -g expo-cli


tia*_*dws 12

似乎是一个错误。如果我安装@types/react在 Expo 请求的特定版本上,它就可以工作 ( 17.0.21)。

yarn add --dev @types/react@17.0.21
Run Code Online (Sandbox Code Playgroud)