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

Provide .mjs entry for native ESM #1217

Closed
jaydenseric opened this issue Jan 30, 2018 · 2 comments
Closed

Provide .mjs entry for native ESM #1217

jaydenseric opened this issue Jan 30, 2018 · 2 comments

Comments

@jaydenseric
Copy link

This will make it possible for packages dependant on graphql to in turn do the same for their consumers, without encountering babel/babel#7294.

Node.js with --experimental-modules can run ESM in .mjs files.

Essentially, package.json needs to go from this:

{
  "main": "index.js",
  "module": "module/index.js"
}

To this:

{
  "main": "index",
  "module": "index.mjs"
}

Sibling index.js (CJS) and index.mjs (ESM) files need to be published. Node.js will load the relevant file, looking up .mjs before .js for main if --experimental-modules is enabled.

@leebyron
Copy link
Contributor

I'm happy to entertain PRs that add this functionality to the build process. We already produce module files, which are used by rollup and other ES6 aware bundlers. Is all that necessary is changing file extension?

leebyron added a commit that referenced this issue Feb 14, 2018
* Writes .mjs instead of .js for code within ./module
* Add a top level index.mjs file (which simply redirects to ./module)

Fixes #1217
@leebyron
Copy link
Contributor

@jaydenseric I just put up a PR which seeks to support this case - would you might helping out with a test case? Even if you want to just pull down the PR and run the build to see if the resulting output solves things for you

leebyron added a commit that referenced this issue Feb 15, 2018
* Writes .mjs instead of .js for esmodules code.
* Moves .mjs out of ./module into the top level since it no longer conflicts with .js

Fixes #1217
leebyron added a commit that referenced this issue Feb 15, 2018
* Writes .mjs instead of .js for esmodules code.
* Moves .mjs out of ./module into the top level since it no longer conflicts with .js

Fixes #1217
leebyron added a commit that referenced this issue Feb 15, 2018
* Writes .mjs instead of .js for esmodules code.
* Moves .mjs out of ./module into the top level since it no longer conflicts with .js

Fixes #1217
@jaydenseric jaydenseric changed the title Provide .mjs enty for native ESM Provide .mjs entry for native ESM Feb 21, 2018
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

No branches or pull requests

2 participants