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

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

Closed
veeramarni opened this issue Aug 5, 2024 · 5 comments · Fixed by #8738
Closed

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

veeramarni opened this issue Aug 5, 2024 · 5 comments · Fixed by #8738

Comments

@veeramarni
Copy link

提问前先看看:

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
Copy link

Soumako commented Aug 13, 2024

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

@navid-kalaei
Copy link

The cause of the error is this commit 455b4f1. 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/[email protected]

References:

#8606
455b4f1

@veeramarni
Copy link
Author

veeramarni commented Sep 7, 2024

@sushi-su 455b4f1

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

@vojty
Copy link
Contributor

vojty commented Sep 24, 2024

There are actually 2 problems:

  1. CJS build uses ESM module lodash-es - I believe this should be fixed by replacing lodash-es -> lodash during the build step
  2. ESM build is missing exports definition in package.json, which causes problems when using for example vitest (vitest uses nodejs resolver that detects ESM by exports attribute, not module). The packages are recognized as CJS which causes 1. again

I have prepared a fix for 2. here #8738 @chenshuai2144 Could you please take a look?

@chenshuai2144
Copy link
Contributor

我将会处理发布新的版本

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

Successfully merging a pull request may close this issue.

5 participants