This rule raises an issue when code imports a polyfill for a feature that is already natively supported by all specified target environments.

Why is this an issue?

Polyfills are JavaScript libraries that provide modern functionality to older environments that don’t support it natively. While polyfills are essential for supporting legacy browsers or older Node.js versions, they become unnecessary overhead when all your target environments already support the feature natively.

Using unnecessary polyfills creates several problems:

Modern build tools and package managers make it easy to accidentally include polyfills even when they’re not needed. This often happens when:

By removing unnecessary polyfills, you can reduce your application’s size, improve performance, and simplify your dependency tree while maintaining the same functionality.

What is the potential impact?

Using unnecessary polyfills increases bundle size and reduces application performance. In large applications, this can significantly impact load times and user experience, especially on slower networks or devices.

How to fix?

Remove the polyfill import and use the native method directly. The native implementation will be available in all your target environments.

Non-compliant code example

import assign from 'object-assign';

const result = assign({}, obj1, obj2); // Noncompliant

Compliant code example

// No import needed - Object.assign is natively supported
const result = Object.assign({}, obj1, obj2);

Documentation