ant-design / pro-components

🏆 Use Ant Design like a Pro!
https://pro-components.antdigital.dev
MIT License
4.04k stars 1.29k forks source link

🐛[BUG] antd 4 中未暴露 theme,编译报错 #5851

Closed yee94 closed 1 year ago

yee94 commented 1 year ago

提问前先看看:

https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md

🐛 bug 描述

import { ConfigProvider as AntdConfigProvider, theme as antdTheme } from 'antd';

Antd 4 中未暴露 theme 属性,当前编译报错

© 版本信息

🚑 其他信息

image
liuhuapiaoyuan commented 1 year ago

这个问题太坑了。。这2天正好在弄。。。结果给卡住了

hustcer commented 1 year ago

这个什么时候能修复呢?等着用,谢谢

hqwlkj commented 1 year ago

同问

xukechu commented 1 year ago

确实有这个问题,暂时写了个脚本启动前在ES文件写入了export const theme = null;临时解决了下,不然vite下完全用不了。

baidan4855 commented 1 year ago

确实有这个问题,暂时写了个脚本启动前在ES文件写入了export const theme = null;临时解决了下,不然vite下完全用不了。

照你的方法处理完以后还会有新的错误 `Remix App Server started at http://localhost:3000 (http://172.16.0.232:3000) /Users/user/test-proj/node_modules/@ant-design/pro-components/es/index.js:1 export * from '@ant-design/pro-card'; ^^^^^^

SyntaxError: Unexpected token 'export' at wrapSafe (internal/modules/cjs/loader.js:1001:16) at Module._compile (internal/modules/cjs/loader.js:1049:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) at Module.load (internal/modules/cjs/loader.js:950:32) at Function.Module._load (internal/modules/cjs/loader.js:790:14) at Module.require (internal/modules/cjs/loader.js:974:19) at require (internal/modules/cjs/helpers.js:92:18) at Object. (/Users/user/test-proj/app/routes/index.jsx:2:38) at Module._compile (internal/modules/cjs/loader.js:1085:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) GET / 500 - - 38.846 ms`

xukechu commented 1 year ago

是在antd/es/index.js文件下追加一个"export const theme = null;"

xukechu commented 1 year ago

确实有这个问题,暂时写了个脚本启动前在ES文件写入了export const theme = null;临时解决了下,不然vite下完全用不了。

照你的方法处理完以后还会有新的错误 `Remix App Server started at http://localhost:3000 (http://172.16.0.232:3000) /Users/user/test-proj/node_modules/@ant-design/pro-components/es/index.js:1 export * from '@ant-design/pro-card'; ^^^^^^

SyntaxError: Unexpected token 'export' at wrapSafe (internal/modules/cjs/loader.js:1001:16) at Module._compile (internal/modules/cjs/loader.js:1049:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) at Module.load (internal/modules/cjs/loader.js:950:32) at Function.Module._load (internal/modules/cjs/loader.js:790:14) at Module.require (internal/modules/cjs/loader.js:974:19) at require (internal/modules/cjs/helpers.js:92:18) at Object. (/Users/user/test-proj/app/routes/index.jsx:2:38) at Module._compile (internal/modules/cjs/loader.js:1085:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) GET / 500 - - 38.846 ms`

`import path from "path"; import fs from "fs/promises";

/**

shim(); `

baidan4855 commented 1 year ago

我直接把这个文件修改了下,在末尾加上这个导出,不过我是用的remix不是vite。

hqwlkj commented 1 year ago

这个配置是添加在哪里的?

@xukechu

xukechu commented 1 year ago

这个配置是添加在哪里的?

@xukechu

node_modules/antd/es/index.js

hqwlkj commented 1 year ago

这个配置是添加在哪里的? @xukechu

node_modules/antd/es/index.js

没有什么作用,会导致其他问题的出现,我以前是使用 vite 一直报错,现在换成了 umi 没有报错了。

Chastrlove commented 1 year ago

https://github.com/ant-design/pro-components/issues/5762#issuecomment-1240310513

faner11 commented 1 year ago
import react from '@vitejs/plugin-react'
import { readFile } from 'fs/promises'
import * as path from 'path'
import { defineConfig } from 'vite'
import ignoreStylePlugin from 'vite-ignore-style'

// https://vitejs.dev/config/
export default defineConfig({
  base: '/indexed-algorithm/',
  plugins: [
    react(),
    ignoreStylePlugin({
      libraryName: 'antd'
    }),
    {
      // 升级antd 5 后删除
      name: 'add-missing-theme',
      apply: 'build',
      transform: (code, id) => {
        const reg = /antd(?:\/|\\{1,2})es(?:\/|\\{1,2})index\.js/
        if (reg.test(id)) {
          return `${code}\nexport const theme = undefined;`
        }
        return code
      }
    }
  ],
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          '@root-entry-name': 'variable'
        },
        javascriptEnabled: true
      }
    }
  },
  resolve: {
    alias: [
      { find: /^~/, replacement: '' },
      {
        find: '@',
        replacement: path.resolve(__dirname, 'src')
      }
    ]
  },
  optimizeDeps: {
    esbuildOptions: {
      plugins: [
        {
        // 升级antd 5 后删除
          name: 'add-missing-theme',
          setup(build) {
            build.onLoad(
              { filter: /antd(?:\/|\\{1,2})es(?:\/|\\{1,2})index\.js/ },
              async (args) => {
                const text = await readFile(args.path, 'utf8')
                return {
                  contents: `${text}\nexport const theme = undefined;`,
                  loader: 'js'
                }
              }
            )
          }
        }
      ]
    }
  }
})
chenshuai2144 commented 1 year ago

下个版本的antd 会支持一下,大家等一等

hsbtr commented 1 year ago

下个版本的antd 会支持一下,大家等一等

在pro-components@2.3.30中还是会出现这个错误,有什么临时修复方法吗

chenshuai2144 commented 1 year ago

关掉 babel import

Boyceman commented 1 year ago

下个版本的antd 会支持一下,大家等一等

哪个版本的antd可以?

hsbtr commented 1 year ago

下个版本的antd 会支持一下,大家等一等

哪个版本的antd可以?

antd 5.x的这个问题已经没有

Boyceman commented 1 year ago

下个版本的antd 会支持一下,大家等一等

哪个版本的antd可以?

antd 5.x的这个问题已经没有

请问4.x有没有好用的版本呢?因为升级antd牵一发动全身,不敢妄动主要是😂

hsbtr commented 1 year ago

下个版本的antd 会支持一下,大家等一等

哪个版本的antd可以?

antd 5.x的这个问题已经没有

请问4.x有没有好用的版本呢?因为升级antd牵一发动全身,不敢妄动主要是😂 这个就不清楚了,可以尝试更到最新的4.x版本