ant-design / pro-components

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

@ant-design/pro-utils version 2.16.0 causing node ssr to fail #8627

Open veeramarni opened 1 month ago

veeramarni commented 1 month ago

提问前先看看:

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

🔩 所属模块或组件

Nodejs pure esm fails

Failed to start server: Error [ERR_REQUIRE_ESM]: require() of ES Module /home/app/node_modules/lodash-es/lodash.js from /home/app/node_modules/@ant-design/pro-utils/lib/transformKeySubmitValue/index.js not supported.
Instead change the require of lodash.js in /home/app/node_modules/@ant-design/pro-utils/lib/transformKeySubmitValue/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/home/app/node_modules/@ant-design/pro-utils/lib/transformKeySubmitValue/index.js:12:17)
    at Object.<anonymous> (/home/app/node_modules/@ant-design/pro-utils/lib/index.js:480:32)
    at Object.<anonymous> (/home/app/node_modules/@ant-design/pro-layout/lib/components/SiderMenu/BaseMenu.js:17:17)
    at async startServer (file:///home/app/server.js:21:37) {
  code: 'ERR_REQUIRE_ESM'
}
/home/app/node_modules/@ant-design/pro-utils/lib/transformKeySubmitValue/index.js:12
var _lodashEs = require("lodash-es");
                ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/app/node_modules/lodash-es/lodash.js from /home/app/node_modules/@ant-design/pro-utils/lib/transformKeySubmitValue/index.js not supported.
Instead change the require of lodash.js in /home/app/node_modules/@ant-design/pro-utils/lib/transformKeySubmitValue/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/home/app/node_modules/@ant-design/pro-utils/lib/transformKeySubmitValue/index.js:12:17)
    at Object.<anonymous> (/home/app/node_modules/@ant-design/pro-utils/lib/index.js:480:32)
    at Object.<anonymous> (/home/app/node_modules/@ant-design/pro-layout/lib/components/SiderMenu/BaseMenu.js:17:17)
    at async startServer (file:///home/app/server.js:21:37) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v18.20.4

Could be related to this https://github.com/ant-design/pro-components/commit/9dffa8f7a467475a308bd9c68a6a0632bf300177#diff-c407fc35e4cbdcbe6777dfcb328fdfc7cea2f2e379ff59cfc4270231e6cecfd9R16
Soumako commented 1 month ago

I encounter this problem too. any solutions? nodejs version: 16.17.1

navid-kalaei commented 1 month ago

The cause of the error is this commit 455b4f1bb1edfd896c04d98c37da6f97fb2428cb. rollback to a version before that which is 7.19.11

here is the commands:

yarn remove @ant-design/pro-layout
yarn add  @ant-design/pro-layout@7.19.11

References:

https://github.com/ant-design/pro-components/pull/8606 https://github.com/ant-design/pro-components/commit/455b4f1bb1edfd896c04d98c37da6f97fb2428cb

veeramarni commented 6 days ago

@sushi-su https://github.com/ant-design/pro-components/commit/455b4f1bb1edfd896c04d98c37da6f97fb2428cb

这不是纯 esm,如果您在 cjs 文件中使用“lodash-es”,它会在 SSR 期间产生错误,因为 Node 不喜欢将 esm 与 cjs 混合。您可以通过生成与 cjs 并行的 .mjs 文件来获得与纯 esm 完全兼容的包。