1 min read

NEXTJS_USE_NATIVE_FETCH

Requires using native `fetch` which Next.js provides, removing the need for third-party fetch libraries.
Table of Contents

Conformance is available on Enterprise plans

This rule is available from version 1.1.0.

Next.js extends the native Web fetch API with additional caching capabilities which means third-party fetch libraries are not needed. Including these libraries in your app can increase bundle size and negatively impact performance.

This rule will detect any usage of the following third-party fetch libraries:

  • isomorphic-fetch
  • whatwg-fetch
  • node-fetch
  • cross-fetch
  • axios

If there are more libraries you would like to restrict, consider using a custom rule.

By default, this rule is disabled. You can enable it by customizing Conformance.

For further reading, see:

This rule will catch the following code.

import fetch from 'isomorphic-fetch';
 
export async function getAuth() {
  const auth = await fetch('/api/auth');
  return auth.json();
}

Replace the third-party fetch library with the native fetch API Next.js provides.

Last updated on May 18, 2024