我试图从react-materialize导入组件

import {Navbar, NavItem} from 'react-materialize';

但是当webpack编译我的.tsx时,它会为上面的-抛出一个错误

ERROR in ./src/common/navbar.tsx
(3,31): error TS7016: Could not find a declaration file for module 'react-materi
alize'. 'D:\Private\Works\Typescript\QuickReact\node_modules\react-materialize\l
ib\index.js' implicitly has an 'any' type.

有什么解决办法吗?我不确定如何解析此导入语句以使用ts-loader和webpack。

react-materialize的index.js是这样的。但是我如何解决这个模块导入在我自己的文件?

https://github.com/react-materialize/react-materialize/blob/master/src/index.js


当前回答

我也遇到过同样的问题,最简单的解决办法就是

NPM I—save-dev @types/react-router-dom

其他回答

工作很好

npm install @types/react-materialize

只要为react安装必要的类型,它就应该解决这个错误。

如果你用的是纱线:

yarn add @types/react @types/react-dom @types/react-router-dom -D

如果你正在使用npm:

npm install @types/react @types/react-dom @types/react-router-dom --save-dev

无法找到模块“react/jsx-runtime”的声明文件

如果有人有这个错误,那么你会惊讶地发现,当使用create-react-app创建react应用程序时,它只在package.json中显示@types/react。但是如果你检查node_modules/@types文件夹,你将找不到任何react文件夹。

解决方案是完全清除node_modules文件夹并重新安装- npm install,或者可能可以使用单个模块安装- npm install @types/react。

我所做的是在项目文件夹目录下从nodejs命令提示符中运行以下命令:

npm init 安装-g webpack NPM install——save react react-dom @types/react @types/react-dom NPM install——保存-dev typescript awesome-typescript-loader source-map-loader NPM安装ajv@^6.0.0 NPM I react-html-id import UniqueId from 'react-html-id';

我做了上面的(虽然我已经安装了npm),它工作!

如果你在使用npm react时遇到问题,请安装——save @types/reactnpm install——save @types/react