nextjs - 💡(How to fix) Fix Docs: Polyfills are not awaited [10 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#83905Fetched 2026-04-08 02:21:13
View on GitHub
Comments
10
Participants
2
Timeline
16
Reactions
1
Author
Participants
Timeline (top)
commented ×10mentioned ×2subscribed ×2issue_type_added ×1

Error Message

console.warn('IntlGetcanonicallocales is not polyfilled'); console.warn('IntlLocale is not polyfilled');

Code Example

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
delete Intl.Locale;
delete Intl.getCanonicalLocales;
console.time('IntlLocale');
// https://formatjs.github.io/docs/polyfills/intl-locale#dynamic-import--capability-detection
import { shouldPolyfill as shouldPolyfillLocale } from '@formatjs/intl-locale/should-polyfill';
// https://formatjs.github.io/docs/polyfills/intl-getcanonicallocales#dynamic-import--capability-detection
import { shouldPolyfill as shouldPolyfillGetcanonicallocales } from '@formatjs/intl-getcanonicallocales/should-polyfill';

if (shouldPolyfillLocale()) {
    if (shouldPolyfillGetcanonicallocales()) {
        await import('@formatjs/intl-getcanonicallocales/polyfill');
        console.log('IntlGetcanonicallocales is polyfilled');
    } else {
        console.warn('IntlGetcanonicallocales is not polyfilled');
    }
    await import('@formatjs/intl-locale/polyfill');
    console.log('IntlLocale is polyfilled');
} else {
    console.warn('IntlLocale is not polyfilled');
}
console.timeEnd('IntlLocale');
RAW_BUFFERClick to expand / collapse

What is the documentation issue?

https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation-client#polyfills

Is there any context that might help us understand?

polyfill import is not awaited. How can i be sure that any code that contains unsupported features will not be executed?

My example (instrumentation-client.ts):

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
delete Intl.Locale;
delete Intl.getCanonicalLocales;
console.time('IntlLocale');
// https://formatjs.github.io/docs/polyfills/intl-locale#dynamic-import--capability-detection
import { shouldPolyfill as shouldPolyfillLocale } from '@formatjs/intl-locale/should-polyfill';
// https://formatjs.github.io/docs/polyfills/intl-getcanonicallocales#dynamic-import--capability-detection
import { shouldPolyfill as shouldPolyfillGetcanonicallocales } from '@formatjs/intl-getcanonicallocales/should-polyfill';

if (shouldPolyfillLocale()) {
    if (shouldPolyfillGetcanonicallocales()) {
        await import('@formatjs/intl-getcanonicallocales/polyfill');
        console.log('IntlGetcanonicallocales is polyfilled');
    } else {
        console.warn('IntlGetcanonicallocales is not polyfilled');
    }
    await import('@formatjs/intl-locale/polyfill');
    console.log('IntlLocale is polyfilled');
} else {
    console.warn('IntlLocale is not polyfilled');
}
console.timeEnd('IntlLocale');

Locally it logs around 100ms and warning printed in dev by https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation-client#performance-considerations

Does the docs page already exist? Please link to it.

https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation-client#polyfills

extent analysis

TL;DR

To ensure that code with unsupported features is not executed before polyfills are loaded, consider awaiting the polyfill imports before executing the code.

Guidance

  • Verify that the polyfill imports are properly awaited in the instrumentation-client.ts file to prevent execution of unsupported features.
  • Review the performance considerations section in the Next.js documentation to optimize the polyfill loading process.
  • Consider adding error handling for cases where the polyfills fail to load or are not supported.
  • Check the browser support for the Intl.Locale and Intl.getCanonicalLocales features to determine if polyfills are necessary.

Example

if (shouldPolyfillLocale()) {
    if (shouldPolyfillGetcanonicallocales()) {
        const getCanonicalLocalesPolyfill = await import('@formatjs/intl-getcanonicallocales/polyfill');
        console.log('IntlGetcanonicallocales is polyfilled');
    } else {
        console.warn('IntlGetcanonicallocales is not polyfilled');
    }
    const localePolyfill = await import('@formatjs/intl-locale/polyfill');
    console.log('IntlLocale is polyfilled');
} else {
    console.warn('IntlLocale is not polyfilled');
}

Notes

The provided code snippet seems to be correctly awaiting the polyfill imports, but the issue might be related to the timing of the execution or the browser support for the features.

Recommendation

Apply workaround: Ensure that all code that uses unsupported features is executed after the polyfills have been loaded, by awaiting the polyfill imports or using a callback function to execute the code after the polyfills have been loaded.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING