Skip to content

[Feature request] CommonJS compatability #152

Closed
@Emsu

Description

@Emsu

CommonJS compatibility
In general, the feature you want added should be supported by HuggingFace's transformers library:

  • If requesting a model, it must be listed here.
  • If requesting a pipeline, it must be listed here.
  • If requesting a task, it must be listed here.

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

Error [ERR_REQUIRE_ESM]: require() of ES Module .pnpm/@[email protected]/node_modules/@xenova/transformers/src/transformers.js from local-vectors/lib/embed.js not supported.
Instead change the require of transformers.js in local-vectors/lib/embed.js to a dynamic import() which is available in all CommonJS modules.
    at local-vectors/lib/embed.js:71:95 {
  code: 'ERR_REQUIRE_ESM'
}

I think you can have the package.json output main, module and types 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions