-
Notifications
You must be signed in to change notification settings - Fork 56
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
Target es5 #48
Target es5 #48
Conversation
Or could you provide an example that works with
run
|
@willrnch thanks for the PR. Whether to still transpile npm packages to ES5 is a hotly debated issue. I'm still on the fence about it, but if I were to do it I would include both es6 and es5 variants. Until then, add this to your package.json:
|
Until ES6 modules get stable: penpal-es5. |
@willrnch, what error were you getting with the solution I proposed? I ran it on a new create-react-app and it seemed to work fine. |
For reference to my future self or others that stumble upon this, here are the related Jest issues that are tracking ES module support: |
Note that Create-React-App transpiles packages from I just tried using this with Next.js, and got the exact same kind of error:
Given the current state of the ecosystem, yes, compiling to ES5 as part of publishing is still the standard approach. I know there's some weird shenanigans you can do to define multiple entry points based on bundling and such. Please rework your publishing to do ES5 first and handle other options as well. Penpal looks like it fulfills a number of my criteria (maintained, simple, TS typings, etc), but at the moment it doesn't look like I can use it in my app due to this. update I was able to get this working with Next.js specifically: // next.config.js
const withPlugins = require('next-compose-plugins');
const withTM = require('next-transpile-modules')(['penpal']);
module.exports = withPlugins([withTM]); Having said that, I'd still request changing the publish step to target ES5/CommonJS as the standard syntax, and include other formats as well in the published archive with appropriate For what it's worth, we use the TSDX build tooling package to publish Redux Toolkit, and it works great for us. Here's what our published package contents look like: |
Alright, I concede. I've added es5 transpilation to v5.1.0, which I just published. es6 should automatically be used when supported by the consumer's bundler, otherwise es5 should automatically be used. Please give it a try and let me know if you run into any issues. |
I get this error using typescript:
Can you configure the build so the |
@willrnch Published in v5.2.0. Thanks for bringing that to my attention. |
@willrnch, I modified how this is done in v5.2.1. Rather than making duplicate type files in the |
Also, I'm still new to dealing with type declarations, so I'm trying to balance what qualifies as a breaking change. This may be one of those things that should have been considered a breaking change if developers were importing type files directly from the |
When targeting
es6
, the build usesimport export
style module. Therefore, when includingpenpal
in a project usingjest
, the code must be transpiled first.