-
Notifications
You must be signed in to change notification settings - Fork 785
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
[Feature request] CommonJS compatability #152
Comments
The distributed npm package already contains a CJS file, so transformers.js "can compile to both CJS and ESM" already? Not sure how you run into that error or what your entire build setup looks like, can you share a test repo/setup to inspect? If you don't use the distributed ES5 bundle but ES6 as it is, you need to use And there already is a
In any case, you can already just use the distributed ES5 file and just keep your legacy stack (which I wouldn't recommend though, because it's legacy for a reason and ES6 is better in so many ways - and every browser supports it). |
@Emsu For your use-case, are you not able to use the dynamic That said, if it is simple to also distribute the library as a CommonJS module (hopefully only 1-2 files in |
I think this would help fix this issue in LangChain, langchain-ai/langchainjs#2992 |
Hi, Even i tried using v3 branch but still same issue Kindly guide us in this |
To be specific, this comment langchain-ai/langchainjs#2992 (comment) was the only thing that worked for me out of everything I've tried. const TransformersApi = Function('return import("@xenova/transformers")')();
const { pipeline } = await TransformersApi; |
what is the difference between using :
and directly using :
the first one works but the second throw error on runtime with "...dynamic import() which is available in all CommonJS modules" logically i don't see the difference but for some reason one worked and one did not, both of them are inside "async" function and using CommonJs. |
CommonJS compatibility
In general, the feature you want added should be supported by HuggingFace's transformers library:
We're hoping in addition to ESM, that transformers.js can compile to both CJS and ESM targets.
Reason for request
Why is it important that we add this feature? What is your intended use case? Remember, we are more likely to add support for models/pipelines/tasks that are popular (e.g., many downloads), or contain functionality that does not exist (e.g., new input type).
It's important for the wider audience of Javascript and typescript developers to be able to use the library especially those working in codebases where it'd be difficult to move everything to ESM.
Additional context
Add any other context or screenshots about the feature request here.
Here's the main error I get when I try to use the package
I think you can have the
package.json
outputmain
,module
andtypes
for CJS, ESM and TS support.Here's two reference articles on the web:
https://adamcoster.com/blog/commonjs-and-esm-importexport-compatibility-examples
https://antfu.me/posts/publish-esm-and-cjs
The text was updated successfully, but these errors were encountered: