代码之家  ›  专栏  ›  技术社区  ›  Anh Pham

模块生成失败:重复声明

  •  0
  • Anh Pham  · 技术社区  · 8 年前

    我正在我的React项目中使用Ant设计框架。但在导入组件时,它会发出一个错误,即使我以前没有声明这些组件。

    错误:

    Module build failed: Duplicate declaration "Icon"
    

    代码如下:

    // App.js
    
    import React from 'react';
    import ReactDOM from 'react-dom';
    import { FullSpinner } from "./Spinner"
    
    class App extends React.Component {
      render() {
        return (<div>sdkfjsdf</div>)
      }
    }
    
    export default App 

    // Spinner.js
    
    import { Spin, Icon } from 'antd';
    
    import React from 'react'
    import {Icon, Spin} from 'antd';
    
    const antIcon = () => <Icon type="loading" style={{ fontSize: 24 }} spin />;
    
    
    export const FullSpinner = () => <Spin indicator={antIcon} />
    2 回复  |  直到 8 年前
        1
  •  2
  •   Gopal Joshi    8 年前

    您已导入 Icon 组件多次。

    // Spinner.js
    
    import { Spin, Icon } from 'antd';
    import React from 'react'
    import {Icon, Spin} from 'antd';  <- Duplicate
    
    const antIcon = () => <Icon type="loading" style={{ fontSize: 24 }} spin />;
    export const FullSpinner = () => <Spin indicator={antIcon} />
    

    删除后重试 import { Spin, Icon } from 'antd'; 从…起 Spinner.js

        2
  •  1
  •   thgaskell    8 年前

    你的 Spinner.js 文件正在导入 Spin Icon 两次从 antd 单元您可以安全地删除其中一条线。

    // Spinner.js
    
    import React from 'react'
    import {Icon, Spin} from 'antd';
    
    const antIcon = () => <Icon type="loading" style={{ fontSize: 24 }} spin />;
    
    
    export const FullSpinner = () => <Spin indicator={antIcon} />