bundlephobia
bundlephobia copied to clipboard
Bundlephobia does not support modern language features.
See comments for further details. I have unpublished the packages that the original post mentioned.
No details are given in the error aside from "Failed to build this package."
I did some testing and have discovered that three aspects of my code were causing the build error.
The "static" keyword:
class Foo {
static bar = 0;
}
class Foo {
#bar;
constructor() {
this.#bar = 0;
}
}
Arrow function expression methods:
class Foo {
bar = () => console.log('Hello, world!');
}
All three are supported by the newest version of Terser.
The package I linked in the original example has been renamed and changes were made within the code so that it would bundle correctly. It would still be nice for this to work for other packages, though.
It seems like the nullish coalescing operator:
const foo = (bar) => bar ?? 0;
and optional chaining:
foo?.bar?.();
also cause build errors. Both are also supported by the newest version of Terser.
The issue comes from the package-build-stats
package. An issue there (https://github.com/pastelsky/package-build-stats/issues/33) already exists.
Most recent PR: https://github.com/pastelsky/package-build-stats/pull/35
Update on supporting modern language features: This is taking a lot longer than I expected primarily because this is a big change. Firstly, I'd have to change bundlephobia's bundler. Secondly, any change in bundler means that all existing results need to be refreshed since a change in bundler is likely to cause a change in baseline (e.g. Webpack 5 does much better tree shaking). There are two ways of going about this β
- Upgrade to Webpack 5: is a large upgrade from Webpack 4 and all existing tooling (including composition calculation etc) needs to be ported over. I'd done a prototype for this, but turns out to my surprise that Webpack 5 is in general, 20-30% slower than Webpack 4 for large packages. This means slower package build or me bumping up server capacity by that amount β both of which aren't very desirable. Also, given how painful webpack upgrades are, and how tonnes of loaders and plugins, each with their own upgrade paths is required, I'm less excited about choosing this.
- Switch to a faster modern bundler: I've been eyeing moving to Parcel 2, and did a prototype that gave some very promising results. The configuration is much easier to manage, and bundling is a lot faster. This is my current choice, and will continue to port over bundlephobia's features to Parcel β it will take time though.
All of this is going to take a month or so, given holidays and my work schedule. Apologies for not responding on the thread sooner, but I thought I'd share an update because it's not like I've not been thinking about this problem β its just a lot of work.
Note: Bundlephobia should now support new javascript syntax β all that's supported by the latest version of Acorn and Terser β reasonably well, while I continue to work on replacing our bundler under the hood.
This was long due βΒ thanks a lot for all of your patience!