Skip to content

ESM Compatibility issue #39

@DellanX

Description

@DellanX

Describe the bug

To simplify the process of migrating to TypeConfiguration classes from Declarators, I created a library for housing my models. That all worked fine, and I am set up to finish the migration. Unfortunately, I ran into a speed bump. No matter how I configure my build and test configurations, I run into import CJS issues with this library (as well as entity-store and json-api-entity-provider). Thing is... I am using ESM, not CJS.

I took a deeper look into this library's package.json and dist files, and I think I see the issue.

  1. The package.json uses the legacy configuration, pointing to main module and types, instead of exports`
  2. The es5 and es2015 do not point to subdirectories in a way compatible with strict ESM environments (such as webpack or vitest)

I'd like to pick your brain on solving this. I could easily add a build tool such as unbuild to compile a .cjs and a .mjs file for compatibility. Since your library doesn't output a .cjs or .mjs file, I think this wouldn't break compatibility. That said, I really don't have experience with UMD vs. ES5 vs. ES2015 vs. ESM.

Let me know what your thoughts are, if you'd like, I can easily create a draft PR.

  • in the meantime, I may setup a project on UMD, ES5 and ES2015 to verify compatibility

To Reproduce

Steps to reproduce the behavior:

  1. Build this library
  2. Check to see if index.js points to subfolders such as functions by syntax ./functions/index

OR

  1. Create a library and define some models
  2. Add the library to an app, and check that tools such as webpack or vitest run

The log I get, when I brute force ESM:

data-api\node_modules\@dipscope\entity-store\dist\es2015\command-builders' is not supported resolving ES modules imported from data-api\node_modules\@dipscope\entity-store\dist\es2015\index.js

Expected behavior

The ideal solution, would be the ability to consume this library in another library, and import that library in an app.

  • ESM would be nice, as that allows for named imports.

Screenshots

If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows
  • Browser: ESM based node (vitest)

Additional Context

Again, I don't mind adding in build tools and configuring them. I just want to run the idea by you first, and see what you'd like the outcome of the changes to look like. (For example, do you want to make sure that ES5/ES2015/UMD are output, or is just CJS/ESM fine, or all of the above)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions