question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposals are not polyfilled by babel-preset-gatsby

See original GitHub issue

Description

We recently started using Promise.allSettled in our application code. This is correctly pulled into the polyfill bundle because some browsers don’t support it yet.

The gatsby babel preset currently uses core-js@3 to polyfill syntax that is not supported by whatever browserslist config your project uses. However, if a particular syntax is a proposal (e.g. Promise.allSettled: https://github.com/zloirock/core-js/blob/master/packages/core-js/proposals/promise-all-settled.js) this is currently not polyfilled automatically.

This is confusing for developers and solvable by simple configuration change to Gatsby’s usage of babel preset env: https://babeljs.io/docs/en/babel-preset-env#corejs

Steps to reproduce

Make a Gatsby project that uses Promise.allSettled somewhere in the code.

Expected result

Promise.allSettled polyfill is added to polyfills.js, as well as the application code, and Safari 12 loads the inlined Promise.allSettled polyfill since it doesn’t have that native method.

Actual result

Promise.allSettled polyfill is added to polyfills.js, not added to the application code, and Safari 12 does not load the polyfill.js backup file due to nomodule directive on the script tag, which Safari 12 understands.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
probablyupcommented, Sep 14, 2020

@wardpeet I went ahead and updated the OP to reflect the new information.

I’m not really in favor of adding more polyfills to Gatsby.

The way the corejs flag in preset env works is only to inline polyfills for syntax that you’re actually using (detected via the “usage” useBuiltIns value which Gatsby already sets.) This is all still based on the browserslist config given to the project. So it’s not really adding more polyfills, unless you yourself decide to use a syntax that would trigger the polyfill to be added.

In gatsby v4 we will deprecate core-js as it adds to much bloat to bundles.

That’s highly subjective and, in my opinion as someone that maintains quite a few open source projects and production applications, not a good idea. If you choose to use a syntax, the platform should do what it can to ensure your code works (within reason.)

Part of the appeal of using a framework like Gatsby is it abstracts away decisions the developer doesn’t want/need to make and allows you to focus on building product. Taking steps away from a good developer experience meaningfully degrades the value of the framework.

0reactions
LekoArtscommented, Mar 23, 2022

Hi!

I’m closing this as a stale issue as in the meantime Gatsby 4 and related packages were released. You can check our Framework Version Support Page to see which versions currently receive active support. If this is a feature request, please create a discussion as we moved feature requests from issues to GitHub Discussions.

Please try the mentioned issue on the latest version (using the next tag) and if you still see this problem, open a new bug report. It must include a minimal reproduction.

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Babel
Polyfills are also automatically added — no more shipping code which ... If you'd like to add custom Babel presets or plugins, you...
Read more >
babel/preset-env
By default, only polyfills for stable ECMAScript features are injected: if you want to polyfill proposals, you have three different options: when using ......
Read more >
babel-preset-gatsby | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
Gatsby Changelog | 5.3.0
The Non-ESM browsers are not polyfilled by default change speeds up the ... chore(babel-preset-gatsby): Updated README to include babel presets PR #35069 ...
Read more >
babel/polyfill - Babel 中文文档
It is automatically loaded when using @babel/preset-env 's useBuiltIns: ... If you need to use a proposal that is not Stage 4, @babel/polyfill...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found