Skip to content

ESM support #83

Description

@angelaraya

Issue type:

  • ➕ Feature request

Description:

With the move to ESM on the server side, there are packages that will stop supporting (or right out removed) CommonJS support. This means that any dependency that only exports as an ES module won't be usable with Components.js.


Some more context

I ran into this issue recently when trying to use sai-js in the Interop Authorization Agent implementation and would appreciate not having to change the codebase to use dynamic imports for no other reason than having to comply with CommonJS.

Activity

  1. github-actions commented on Mar 8, 2022

    @github-actions

    Thanks for the suggestion!

  2. rubensworks commented on Mar 8, 2022

    @rubensworks
    Member

    Components.js currently only supports CommonJS modules indeed.
    The architecture is however ready for ESM support, so it's just a matter of implementing it.

    This is not part of my current roadmap at the moment though (since my projects are all on CJS atm). But I'm happy to give guidance for anyone that wants to submit a PR. (Placing a bounty via the Comunica Association might also be a possibility)


    An easier solution might however be to just expose both the CJS and ESM versions of the sai-js module in its package.json file, which could be done like this: https://github.com/RubenVerborgh/AsyncIterator/blob/main/package.json#L8-L14

  3. rubensworks commented on Mar 8, 2022

    @rubensworks
    Member

    For reference, adding support for loading ESM modules should just be a matter of implementing a new IConstructionStrategy. Currently, we have a ConstructionStrategyCommonJs.ts, where we would require a ConstructionStrategyEsm in the future.

    Most likely, only the implementation of createInstance will be different in ConstructionStrategyEsm compared to ConstructionStrategyCommonJs. So the implementation should be fairly straightforward.

    However, if the desire is to also use Components-Generator.js on ESM projects, that may also require some tweaks in its ResolutionContext

  4. elf-pavlik commented on Mar 10, 2022

    @elf-pavlik

    We were trying to add Conditional exports to sai-js hackers4peace/sai-js#32 but that doesn't seem to solve the problem.

    @woutermont based on the comments above, do you think you would be able to put together a PR with basic support for ESM?

    @angelaraya will you need to use components-generator on sai-js or it is just a matter of IConstructionStrategy?

  5. rubensworks commented on Mar 10, 2022

    @rubensworks
    Member

    We were trying to add Conditional exports to sai-js hackers4peace/sai-js#32 but that doesn't seem to solve the problem.

    @elf-pavlik Does it produce the same error as before?
    Have you tried adding an export entry for package.json, as is done here?: "./package.json": "./package.json",
    (Some background on why that is needed: RubenVerborgh/AsyncIterator#34)

  6. woutermont commented on Mar 10, 2022

    @woutermont
    Contributor

    @elf-pavlik Digita has some packages which use conditional exports succesfully to work both with ComponentsJS and in the browser, so i.m.o. that should work for sai-js as well. Do you have an open PR for that somewhere?

    I will try to look into ESM support next week. Did not think about the generator implications though, so it might be more complex than I expected.

  7. angelaraya commented on Mar 10, 2022

    @angelaraya
    Author

    @woutermont @rubensworks the error with the conditional exports was fixed in sai-js. The only open item would be adding ESM support for componentsjs and the generator.

  8. woutermont commented on Mar 10, 2022

    @woutermont
    Contributor

    Okay, great! So we're temporarily good for sai-ja, as long as we don't need esm-only dependencies, right?

  9. elf-pavlik commented on Apr 5, 2023

    @elf-pavlik

    Has anyone had a chance to look further into adding ESM support?

  10. rubensworks commented on Apr 6, 2023

    @rubensworks
    Member

    No, not that I'm aware of.

  11. elf-pavlik commented on Jun 24, 2024

    @elf-pavlik

    I was updating the testing setup in https://github.com/o-development/solid-notification-client
    To start the latest CSS, everything went well until execution reached the point where CSS dynamically imports oidc-provider, which is an ESM package, where it began throwing errors, complaining about import statements.

    I think supporting ESM could prevent needing to sandwich projects like CSS as CJS between otherwise standard ESM code.

  12. thhck commented on Mar 9, 2025

    @thhck

    I'm also stuck with an ESM only package I want to use in a CSS component.

    Can #145 be merged yet or more need to be done ?

  13. jeswr commented on Aug 11, 2025

    @jeswr
    Contributor

    Can #145 be merged yet or more need to be done ?

    More work required - I think the point at which I got stuck in the process and then ran out of time was this having a circular dependency with comunica

  14. elf-pavlik commented on Aug 11, 2025

    @elf-pavlik

    I'm trying to add CSS repo as git submodule to https://sai.js.org monorepo. Per usual CJS/ESM started biting 😿

    CSS has types shim for oidc-provider https://github.com/CommunitySolidServer/CommunitySolidServer/blob/main/templates/types/oidc-provider.d.ts
    to address microsoft/TypeScript#49721

    TS supposedly fixed that issue, but when I tried to remove the shim from CSS the rabit hole of CJS opens again.
    I don't have cycles available to try contribute to this issue myself, but it would be amazing if someone finally was able to finish this ESM support. I'm sure @jeswr's work is a great headstart.

  15. thhck commented on Sep 5, 2025

    @thhck

    @jeswr seems like a complex issue. I'm quickly looking at your branch, and I see it's currently failing 3 tests suites.

    Would passing all the tests means the issue is solved ?

  16. elf-pavlik commented on Sep 5, 2025

    @elf-pavlik

    @thhck I have also been looking at that branch and posted some comments in comunica/comunica#930 (comment)

    Besides that I made related PR to CSS CommunitySolidServer/CommunitySolidServer#2057

    If you like we could team up next week to make more progress. We could also use some time during Soild CG weekly meeting if we are all present.

  17. thhck commented on Sep 5, 2025

    @thhck

    Sounds good !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions