Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.0.0 版本 export 'theme' (imported as 'antdTheme') was not found in 'antd' #5762

Closed
oswayne opened this issue Aug 23, 2022 · 12 comments
Closed

Comments

@oswayne
Copy link

oswayne commented Aug 23, 2022

🧐 问题描述

依赖:

"dependencies": {
    "@ant-design/icons": "^4.7.0",
    "@ant-design/pro-components": "^2.0.0",
    "axios": "^0.27.2",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.3.0",
    "react-scripts": "5.0.1"
  },

Index.js

import React from 'react';
import ReactDOM from 'react-dom/client';
import {BrowserRouter, Route, Routes} from "react-router-dom";

import 'antd/dist/antd.min.css';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<BrowserRouter>
    <Home/>
</BrowserRouter>);

启动后控制台信息:

Failed to compile.

Attempted import error: 'theme' is not exported from 'antd' (imported as 'antdTheme').
ERROR in ./node_modules/@ant-design/pro-utils/es/useStyle/index.js 35:69-78
export 'theme' (imported as 'antdTheme') was not found in 'antd' (possible exports: Affix, Alert, Anchor, AutoComplete, Avatar, BackTop, Badge, Breadcrumb, Button, Calendar, Card, Carousel, Cascader, Checkbox, Col, Collapse, Comment, ConfigProvider, DatePicker, Descriptions, Divider, Drawer, Dropdown, Empty, Form, Grid, Image, Input, InputNumber, Layout, List, Mentions, Menu, Modal, PageHeader, Pagination, Popconfirm, Popover, Progress, Radio, Rate, Result, Row, Segmented, Select, Skeleton, Slider, Space, Spin, Statistic, Steps, Switch, Table, Tabs, Tag, TimePicker, Timeline, Tooltip, Transfer, Tree, TreeSelect, Typography, Upload, message, notification, version)

webpack compiled with 1 error
@BestDingSheng
Copy link

我也碰到了这个问题

@sushi-su
Copy link
Contributor

应该是发错版本了,v2 得搭配 antdv5 使用

@BaoXiaoShuai
Copy link

一样的问题

@chenshuai2144
Copy link
Contributor

这个没办法去掉,可以先忽略,
我们兼容了一下 antd 版本,但是warning 去不掉

@criejs
Copy link

criejs commented Aug 25, 2022

我也遇到了,导致 umi/max 项目升级,在vite模式下,直接崩溃了

@gaofengGo
Copy link

这个没办法去掉,可以先忽略, 我们兼容了一下 antd 版本,但是warning 去不掉

大佬,项目用的是 vite 的话不仅仅是警告,项目启动和 build 都报错了

@Chastrlove
Copy link

Chastrlove commented Sep 8, 2022

报error可能是因为设置了strictExportPresence:true, webpack的可以使用如下配置。

  ignoreWarnings: [
      /export 'theme' \(imported as 'antdTheme'\) was not found in 'antd'/
    ],

@Chastrlove
Copy link

如果是vite,可以自定义个插件

optimizeDeps: {
    esbuildOptions: {
      plugins: [
        {
          name: "add-missing-theme",
          setup(build) {
            build.onLoad({ filter: /antd(?:\/|\\{1,2})es(?:\/|\\{1,2})index\.js/ }, async(args) => {
              let text = await fs.promises.readFile(args.path, 'utf8')
              return {
                contents: `
              ${text}\nexport const theme = undefined;
              `,
                loader: "js",
              };
            });
          },
        },
      ],
    }
  },

@hqwlkj
Copy link
Contributor

hqwlkj commented Sep 8, 2022

esbuildOptions: {
      plugins: [
        {
          name: "add-missing-theme",
          setup(build) {
            build.onLoad({ filter: /antd(?:\/|\\{1,2})es(?:\/|\\{1,2})index\.js/ }, async(args) => {
              let text = await fs.promises.readFile(args.path, 'utf8')
              return {
                contents: `
              ${text}\nexport const theme = undefined;
              `,
                loader: "js",
              };
            });
          },
        },
      ],
    }

这样配置 了编译不报错,但是 运行时还是会报于这相关的错误信息

image

@Ariaszzzhc
Copy link

@hqwlkj 这个问题我发现是由于 SWR 的版本问题。使用 1.2.0 的 swr 就可以正常运行

@hqwlkj
Copy link
Contributor

hqwlkj commented Sep 8, 2022

swr

没有使用到 swr 这个依赖
image

@hsbtr
Copy link

hsbtr commented Nov 8, 2022

报error可能是因为设置了strictExportPresence:true, webpack的可以使用如下配置。

  ignoreWarnings: [
      /export 'theme' \(imported as 'antdTheme'\) was not found in 'antd'/
    ],

pro-components@2.3.30,使用这个方法还是失效了,webpack直接终止了编译,看来暂时没法用了
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests