-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Distributing ES6 by default is confusing/premature #601
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
Comments
Maybe we could investigate trying out https://github.com/developit/microbundle or https://github.com/pikapkg/pack |
distribution is a big mess tbh, but i think the way we're doing it is actually fairly common. The lib is transpiled using babel-env on ">1%, not dead, not ie 11, not op_mini all". As for esm, webpack handles esm by default, all bundlers do. You don't need to include node_modules for this
Sounds great to me. But i think the problem is the same: no one knows what the baseline is. If we set IE11 as the baseline we add a ton of weight and make the lib slower for 99% of the end-users that use modern browsers. I do think really old browsers are the concern of the end-user. This is the same philosophy that create-react-app follows, their config is:">0.2%, not dead, not ie 11, not op_mini all".
I don't think it does that, because Jest reads out package.json and picks the commonjs exports automatically. All SSR and testing libs use the main field, not module.
All these issues are fixed. It was something else that caused it. When renderprops and hooks had to be two exports, only one could be declared in package.json. So if you use renderprops, jest would pick esm and choke. That happens no more because the default export for renderprops is cjs by default and hooks is fine since gatsby/next/jest pick main, which leads to cjs. |
Here's a simple example repo where Jest fails when importing: It's fixed by importing from A different problem that is also fixed by appending
The CRA default config targeting evergreen browsers applies to your own app code; CRA isn't used to develop libraries. The norm for libraries is to provide ES5 by default, and this norm is reflected, for example, in webpack's default config excluding The |
I second this. Updating to react-spring v8 on a project using |
For starters, it'd be useful to understand why the issue is happening in Jest even though the Something I've realized from this is that UglifyJS only supporting ES5 is a feature, at least if more legacy browsers are targeted, since it prevents untranspiled dependencies from passing the build step. |
Don’t have access to a laptop right now to make sure, but to me it seems renderprops is a commonjs module https://unpkg.com/[email protected]/renderprops it does not have import and export statements so how can jest choke on it? As for ugliyJS, isn’t it dead? I believe terser is the continued project. |
UglifyJS is widely used and still maintained, and most people don't need support for minifying ES6. |
Terser is a default in webpack and a lot of other tools. UglifyJS is lost my trust when they gave up on uglify-es (this is how terser was born). According browsers support. es5 is not a goal for most users these days. The only ancient browser (IE) is almost dead. So if you really need to support it transpile your dependencies like some developers does to support es3. |
CIU shows support for ES6 at around 90-95%, so it's usually a business requirement to support those 5-10% of legacy browsers, and I'm reasonably certain that most people don't expect to have to transpile dependencies. UglifyJS not supporting ES6 is a feature, not a flaw, in this context, since untranspiled libraries make it fail at the build step instead of in the browser, which is the worst case scenario. The date-fns solution is interesting, although it's unfortunate that it requires all the files being named |
5-10% is not a good reason to increase bundle size of 90-50%. Terser has ecma version options Date-fns solution does not require files to be named |
Do you have a source for the bundle size increase? terser docs say "this setting is not presently enforced" about the Thanks for the react-transition-group example; it seems like the all-around best approach. |
It's not about terser. Transpiled classes are much bigger. Function expression is bigger than arrow etc. |
I would guess that the size difference from downlevel-compiling to ES5 would be mostly offset by compression, since the code is repetitive. The 90-50% figure seems way too large. The two relevant issues are distributing both node and ES modules and distributing both ES5 and ESNext code. The module part is solved reasonably well by having separate The default being ESNext is additionally problematic in that it's a trap for users that support legacy browsers like IE11 and don't expect to have to transpile dependencies, because the norm is to distribute ES5. For example, if my build pipeline didn't involve UglifyJS, importing |
could we give it a better name? or maybe adding a rollup ".legacy" slot would do it. you could submit a pr if you like, not opposed to something waterproof in legacy situations. just throwing this on everyones shoulders isn't what i'd like to do. |
PS. the file that builds all of these targets: https://github.com/react-spring/react-spring/blob/master/rollup.config.js |
React Spring distributes ES6 by default, which breaks jest tests unless it's imported explicitly using the cjs extension. See pmndrs/react-spring#601
Running into issues as well. Don't know if they relate to this, but it looks like it. When trying to build on server which uses SSR, I get the following:
|
Please, this would fix all the issues i'm having in typescript land with spring in terms of transpiling targetting commonjs |
In version 9.0.0-beta.12, when using both Typescript and a react-spring submodule e.g.
importing from
|
@minheq The latest beta fixes all that. Thanks for the report! 👍 |
@aleclarson would you mind pointing to the PR that fixes the issue? |
Hi @aleclarson can you share what approach react-spring went ahead with in v9? While using v8, I've changed my imports from "react-spring/renderprops" to "react-spring/renderprops.cjs" I think the best solution would have been what @TrySound suggested, creating individual package.json for all possible export files. I think that would also work with https://github.com/prateekbh/babel-esm-plugin/ or https://philipwalton.com/articles/using-native-javascript-modules-in-production-today/ without having to transpile anything in node_modules. |
@azizhk The current v9 beta exports the renderprops API from import { Spring } from 'react-spring/web.cjs' Not sure what the solution for v8 is. I'm not contributing to it. |
@aleclarson in this comment you mentioned:
But in the documentation, it still uses Is documentation outdated? or we should use |
I would check the link in the repo for more up to date documentation. Updating the site is on my list of to-dos. |
The same problem in v9.0.0, CI logs with jest. workaroud solution is '.cjs' in the end of import, but you lose Types for typescript 😞 |
@Luchanso if you want to open a new issue and follow the guide, we can look into it when we get to it 😄 |
@joshuaellis Is the website made from .md files on this repository? (I just could not find the website on this repo) |
Thank you 😃 I found solution of my problem |
No, there's the current (outdated) website react-spring.io, then there is a small microsite containing some documentation on v9 – https://aleclarson.github.io/react-spring/v9/, unfortunately, this was the way it was left.... |
Libraries are almost universally distributed as transpiled modules with the node module format as a baseline, so the typical setup is to exclude dependencies in
node_modules
from transpilation. The documentation states that:Meaning that the use case supported by default is serving ES modules to browsers, which is really bleeding edge and requires a complex setup with bundling as fallback, etc. The experimental module support in node also works differently and uses
.mjs
files, so there is uncertainty what the proper way of using modules will be going forward.The issues the current approach causes are, for example, either requiring special config to run in Jest and to be bundled for browsers, or importing the
.cjs
module paths. It would make more sense and reduce the number of issues users are having to make ES modules be the special case and node modules be the default. It should, as a minimum, be better documented, since having to import from a special path gives the impression of being a workaround.Examples of issues: #494 #555 #599 and others. #555 in particular gives only a partial solution which works just for Jest but would still fail for bundling or running the code.
The text was updated successfully, but these errors were encountered: