ant-design / ant-design

An enterprise-class UI design language and React UI library
https://ant.design
MIT License
92.36k stars 49.58k forks source link

`5.17.1` introduce a bug of import `es` module in `lib` #48913

Closed arvinxx closed 5 months ago

arvinxx commented 5 months ago

Reproduction link

https://github.com/lobehub/lobe-chat/tree/failed-with-deps/antd-5.17.1

Steps to reproduce

git clone https://github.com/lobehub/lobe-chat

git checkout failed-with-deps/antd-5.17.1

pnpm i / npm i / bun i

npm run test

What is expected?

test pass

What is actually happening?

test error with:

SyntaxError: Cannot use import statement outside a module
 ❯ Object.<anonymous> node_modules/antd/lib/alert/Alert.js:18:13

Module /home/runner/work/lobe-chat/lobe-chat/node_modules/rc-util/es/ref.js:1 seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package "rc-util" asking them to ship the file in .mjs extension or add "type": "module" in their package.json.

As a temporary workaround you can try to inline the package by updating your config:

// vitest.config.js
export default {
  test: {
    server: {
      deps: {
        inline: [
          "rc-util"
        ]
      }
    }
  }
}

I think it's a bug of import es module in lib folder:

image

Environment Info
antd 5.17.1
React 18
System any
Browser any
hiql commented 5 months ago

同样的问题,升级前也只是一些finddom的警告,升级后程序崩快了

/Users/hiql/workspace/lt-projects/lingtan/node_modules/rc-util/es/ref.js:1
import _typeof from "@babel/runtime/helpers/esm/typeof";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (node:internal/modules/cjs/loader:1389:18)
    at Module._compile (node:internal/modules/cjs/loader:1425:20)
    at Module._extensions..js (node:internal/modules/cjs/loader:1564:10)
    at Module.load (node:internal/modules/cjs/loader:1287:32)
    at Module._load (node:internal/modules/cjs/loader:1103:12)
    at Module.require (node:internal/modules/cjs/loader:1310:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/Users/hiql/workspace/lt-projects/lingtan/node_modules/antd/lib/alert/Alert.js:18:13)
    at Module._compile (node:internal/modules/cjs/loader:1480:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1564:10)