简体   繁体   English

找不到模块“react”的声明文件

[英]Could not find a declaration file for module 'react'

I learn Microsoft's manual about TypeScript + React + Redux.我学习了微软关于 TypeScript + React + Redux 的手册

I launched the command:我启动了命令:

npm install -S redux react-redux @types/react-redux

But when I run the command npm run start I get the error:但是当我运行命令npm run start ,出现错误:

Type error: Could not find a declaration file for module 'react'.类型错误:找不到模块“react”的声明文件。 'C:/lab/my-app/node_modules/react/index.js' implicitly has an 'any' type. 'C:/lab/my-app/node_modules/react/index.js' 隐式有一个 'any' 类型。

Ok, I run the command: npm i @types/react .好的,我运行命令: npm i @types/react now I get other error:现在我收到其他错误:

Type error: Module '"../../node_modules/@types/react-redux"' has no exported member 'Dispatch'.类型错误:模块 '"../../node_modules/@types/react-redux"' 没有导出成员 'Dispatch'。 TS2305 TS2305

How can I fix it?我该如何解决?

I had this problem when I initially created a React with TypeScript project, it made no sense since I had not started any work yet.我最初使用 TypeScript 创建 React 项目时遇到了这个问题,因为我还没有开始任何工作,所以没有任何意义。

So in terminal I ran:所以在终端我跑了:

rm -rf node_modules/ && npm install

Then:然后:

npm run start

And I was able to see the main landing page.我能够看到主登陆页面。

运行以下命令: pm install @types/react它对我有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM