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

Fix [ERR_REQUIRE_ESM] error when importing hf_transformers #5746

Merged
merged 2 commits into from
Jun 13, 2024

Conversation

JonaMX
Copy link
Contributor

@JonaMX JonaMX commented Jun 12, 2024

Fixes #2992

const transformers_1 = require("@xenova/transformers");
                       ^
Error [ERR_REQUIRE_ESM]: require() of ES Module .\node_modules\@xenova\transformers\src\transformers.js from .\node_modules\langchain\dist\embeddings\hf_transformers.cjs not supported.
Instead change the require of transformers.js in .\node_modules\langchain\dist\embeddings\hf_transformers.cjs to a dynamic import() which is available in all CommonJS modules.

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 12, 2024
Copy link

vercel bot commented Jun 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 13, 2024 9:03pm
langchainjs-docs ✅ Ready (Inspect) Visit Preview Jun 13, 2024 9:03pm

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jun 13, 2024
@jacoblee93
Copy link
Collaborator

Hey @JonaMX! Thanks for this and sorry for missing this issue for so long!

I've used an alternate fix involving a dynamic import from one of the other items in the thread. A bit less funky than running a function in a string. But it looks like it fixed it based on the CJS import test I added.

Will merge if it passes CI!

@jacoblee93
Copy link
Collaborator

Thank you for this!

@JonaMX JonaMX deleted the hotifx/hf_transformers branch June 13, 2024 21:32
@sgkadle
Copy link

sgkadle commented Jun 14, 2024

Thank you for this @JonaMX

@SeanCannon
Copy link

@JonaMX is a hero among champions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error [ERR_REQUIRE_ESM] when using HuggingFace Transformers
4 participants