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.

Intl.DateTimeFormat#formatToParts() is not defined in older browsers — please manually polyfill it, example below

See original GitHub issue

In older browsers (I’ve tried IE 9.0, 10, and 11 as well as Firefox 52 and 56), attempting to load the cart produces:

TypeError: a.formatToParts is not a function

Thoughts on a potential polyfill?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
TracerBuiltcommented, Nov 21, 2020

Thank you so much. This is extremely helpful.

0reactions
andria-devcommented, Nov 21, 2020

Here is a link to my project that utilizes an optional polyfill loading pattern:

https://github.com/ChrisBrownie55/notably/blob/dabe00a22c8db1d18cc7f49fd7ef866138b4ecdc/src/index.tsx#L50-L59

The idea is that you can create some asynchronous functions that see if a polyfill is needed for a feature and then will load each polyfill and assign them to their respective names on the window. Once you have these, you can run them all and use Promise.all() to wait for all of them.

Once all of the asynchronous functions have ended, you can then import your App.js file dynamically and render it. The reason why we wait to import App.js is that if we try to use one of those features — used in the module’s global scope, not in a component/function — that need to be polyfilled within our app before it is polyfilled, then our app will crash.

async function loadXyz() {
	if (!window.xyz) {
		window.xyz = (await import('xyz-polyfill')).default
	}
}

async function loadAbc() { /* ... */ }

Promise.all([loadXyz(), loadAbc()])
	.then(() => import('./App.js'))
	.then(({ default: App }) => {
		// render
		ReactDOM.render(<App />, document.getElementById('root'));
	})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Intl.DateTimeFormat.prototype.formatToParts() - MDN Web Docs
The formatToParts() method is useful for custom formatting of date strings. It returns an Array of objects containing the locale-specific ...
Read more >
NPM package lacks browser support. Polyfill/Babel to fix?
dateTimeObj.toFormat() will try to use Intl.DateTimeFormat.prototype.formatToParts() not supported until Safari 11. Is it the case that the ...
Read more >
Formatting Date and Time with Intl.DateTimeFormat
Intl.DateTimeFormat is an easy tool to formatting date and time without adding extra KB to your bundle size.
Read more >
4 alternatives to Moment.js for internationalizing dates
RelativeTimeFormat , you can use the methods format() or formatToParts() (that returns an array with the parts of the output) to format a...
Read more >
Index
In addition to objects that are predefined in the browser, you can define your ... formatToParts(), DateTimeFormat, Internationalization, Intl, JavaScript, ...
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