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

[Bug]: ERR_REQUIRE_ESM: lodash-es is esm package, use mergeDocConfig from @rspress/shared/dist/node-utils.js will failed #1655

Closed
liuwenzhuang opened this issue Dec 11, 2024 · 4 comments · Fixed by #1656
Labels
🐞 bug Something isn't working

Comments

@liuwenzhuang
Copy link
Contributor

Version

System:
    OS: Linux 5.15 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    Memory: 10.97 GB / 15.62 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  npmPackages:
    rspress: ^1.38.0 => 1.38.0

Details

after build, @rspress/shared/dist/node-utils.js likes:

// src/node-utils/merge.ts
var import_lodash_es = require("lodash-es");

but lodash-es is esm package, requie will failed:

var import_lodash_es = require("lodash-es");
                       ^

Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/.pnpm/[email protected]/node_modules/lodash-es/lodash.js from node_modules/.pnpm/@[email protected]/node_modules/@rspress/shared/dist/node-utils.js not supported.
Instead change the require of lodash.js in node_modules/.pnpm/@[email protected]/node_modules/@rspress/shared/dist/node-utils.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (node_modules/.pnpm/@[email protected]/node_modules/@rspress/shared/dist/node-utils.js:64:24) {
  code: 'ERR_REQUIRE_ESM'
}

Reproduce link

nope

Reproduce Steps

nope

@liuwenzhuang liuwenzhuang added the 🐞 bug Something isn't working label Dec 11, 2024
@Timeless0911
Copy link
Contributor

I will change this to dynamic import then. And I wonder how can you find this API?

@liuwenzhuang
Copy link
Contributor Author

liuwenzhuang commented Dec 11, 2024

I will change this to dynamic import then. And I wonder how can you find this API?

I have a rspress plugin which use this API.

@liuwenzhuang
Copy link
Contributor Author

I will change this to dynamic import then. And I wonder how can you find this API?

change dynamic import will convert mergeDocConfig to async function, does it compatible with plugin?

@Timeless0911
Copy link
Contributor

I will change this to dynamic import then. And I wonder how can you find this API?

change dynamic import will convert mergeDocConfig to async function, does it compatible with plugin?

Plugin hook should also support async function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants