re: Can I publish ES6 to npm? VIEW POST


No you cant - there is no such thing as ES6.

What you can - you can publish as esmodules. These esmodules are not "ES Modules", aka import/export, but a special Babel target which targets some abstract browser, which does support these "ES Modules"(🤷‍♂️), plus stuff like async/await and generators(🔥), but not class members for example.

So - you can publish code in esmodules - import/export and language transpiled down to some "well-known" target. But any "special" babel plugin (or typescript) should do their job and disappear.

After publishing module that way you will have two problems:

  • running code in nodejs/jest - as you said nodejs does not support that stuff well. Use esm for node, and jest-transform for Jest. Drawback - first run, yet without a cache, might be very slow.
  • running code in a lower environment. Like IE11 if you still remember it. Personally I use devolution to de-evolute "ES6" bundle to whatever I need, adding all the polyfils by the way. Another way is to generate old and modern bundle, but that's not as easy.

So - as long as you are removing any "vendor specific" stuff(like stage-1 language features, or babel-plugins) from the package code - it would be ok 👍.

Parcel bundler and CRA would transpile everything automatically, out of the box.

code of conduct - report abuse