gpt4 book ai didi

reactjs - 模块 '"*.svg "' has no exported member ' ReactComponent'

转载 作者:行者123 更新时间:2023-12-02 02:53:57 26 4
gpt4 key购买 nike

我使用 CRA 创建了一个新的 React 应用程序。现在,我想创建一个导出所有图标的索引文件。为此,我将所有图标存储在我的 src/icons 中。文件夹并创建一个索引文件,将我的图标导出为 React 元素。

问题是,我在尝试导出 ReactComponent 时遇到以下错误:

Module '"*.svg"' has no exported member 'ReactComponent'. Did you mean to use 'import ReactComponent from "*.svg"' instead?

enter image description here

根据 CRA's docs ,这应该可以在不需要声明新模块的情况下工作。

我正在使用 react@^16.13.1react-scripts@3.4.1应该支持它。

奇怪的是,当我运行代码时,既没有出现编译错误也没有出现运行时错误。当我使用 <ChevronRightIcon />然后相应地显示图标。

最佳答案

将声明更改为

declare module '*.svg' {
import React = require('react')
export const ReactComponent: React.FC<React.SVGProps<SVGSVGElement>>
const src: string
export default src
}

关于reactjs - 模块 '"*.svg "' has no exported member ' ReactComponent',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61475828/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com