Skip to content

Provide ESM build #67

@NicBright

Description

@NicBright

Hi there

I wonder whether it would be possible for you to provide an ESM compatible build ... ? Why? It's all about the shift of going from require() to import / export style syntax ...

My special use case is this: I'm migrating our code base's unit tests (Jest) to ESM modules, see https://jestjs.io/docs/ecmascript-modules
For this to work, however, the packages need to conform to new ESM modules standards. For example, Jest will fail when it encounters old CommonJS style require() calls. In the case of spark-md5, it is not even possible (for me) to add it to Jest's transformIgnorePatterns (and have it be re-compiled) because (I'm not an UMD expert) it seems to me that the generated UMD file (spark-md5.js) is malformed. So for now I have to copy the whole source code of spark-md5 directly into my code base (in ESM module compatible way) as a workaround.

The new exports property in package.json helps with providing builds delivering modern ESM modules. Being backwards-compatible with old Node.js versions at the same time is easy because old Node.js versions will ignore the exports property and keep referring to package.json's main property instead (so you can still provide a CommonJS build and point to it via main property). If you don't know the new exports property, I recommend a short read of the following resources:

Best Regards,
Nicolas

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions