Skip to content
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

feat!: Added support for ECMAScript Modules (ESM) #338

Closed
wants to merge 1 commit into from

Conversation

yanneves
Copy link

@yanneves yanneves commented May 7, 2021

BREAKING CHANGE: Requires Node version >= 12

This library's coding causes issues with tools like esbuild and vite due to the way it relies on dynamic require() statements. I'm proposing a shift to dynamic imports to introduce support for ES Modules.

The bulk of the changes move imports like this:

var engine = requires.pug || (requires.pug = require('pug'))
// ...

to this:

use('pug').then(engine => {
  // ...
})

Where use() is a utility function that handles import, caching, and additional options, and returns a promise.

Besides bundling a shim for Promise.any(), this runs native. We could consider including more polyfills or building with Babel to support older Node versions. This supersedes #294.

BREAKING CHANGE: Requires Node version >= 12
@yanneves
Copy link
Author

Noticed build failures are due to npm@^7 compatibility issues in the dev dependency tree - I'll try and take closer look 👌

@niftylettuce
Copy link
Collaborator

If you want to be a maintainer and use an ESM version with major semver bump, I am open to adding you.

Submit a new PR and let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants