This rule raises an issue when code imports a polyfill for a feature that is already natively supported by all specified target environments.
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.
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.
Remove the polyfill import and use the native method directly. The native implementation will be available in all your target environments.
import assign from 'object-assign';
const result = assign({}, obj1, obj2); // Noncompliant
// No import needed - Object.assign is natively supported
const result = Object.assign({}, obj1, obj2);