Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Axios throws that the http adapter is not available inside a browser extension

ErrorUncaught (in promise) Error: Error: Adapter 'http' is not available in the build

Short answer

Axios chooses an adapter that fits where it runs: xhr in a browser, http in Node.js, fetch elsewhere. A Manifest V3 extension service worker cannot call XMLHttpRequest, so the xhr route is gone, and a forced http adapter does not exist in a bundle. Tell axios to use the fetch adapter, or call fetch directly.

  • Applies to axios 1.x, Chrome extension Manifest V3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find out where the failing request runs and whether any code sets the adapter option, in a config file or an interceptor.

    grep -rn "adapter" src/ background/ 2>/dev/null
  2. 2Match what you see, then jump to its fix

    1. 1The call is made from the background service worker of the extension, not from a popup or pageThe request runs in a Manifest V3 service worker, where XMLHttpRequest cannot be calledFix
    2. 2A shared axios config file sets adapter to 'http', copied from server codeA config forces adapter: 'http' and the bundler targets the browserFix

What does the error look like?

  • Uncaught (in promise) Error: Error: Adapter 'http' is not available in the build

Cause 1 of 2

The request runs in a Manifest V3 service worker, where XMLHttpRequest cannot be called

1Check

Chrome's extension documentation says XMLHttpRequest cannot be called from a service worker and tells you to use fetch instead. Axios lists its adapters as xhr, http and fetch, and picks the first one the environment supports.

grep -n "service_worker" manifest.json

2Fix

Select the fetch adapter for the axios instance used in the service worker.

import axios from 'axios';

const api = axios.create({ adapter: 'fetch' });
const { data } = await api.get('https://api.example.com/items');

3Verify

Reload the extension, trigger the request from the service worker and watch the console for the error.

# chrome://extensions > your extension > service worker > Inspect

Confirmed by developer.chrome.com

Did this fix it?

Cause 2 of 2

A config forces adapter: 'http' and the bundler targets the browser

1Check

Axios documents the adapter option as a name or an ordered array, and says the http adapter is the one used in Node.js. Code bundled for an extension does not run in Node.js, so a forced http adapter is not what axios can use there.

grep -rn "adapter:" src/ | grep -i http

2Fix

Remove the forced adapter so axios can choose, or give an ordered list that starts with fetch.

const api = axios.create({
  adapter: ['fetch', 'xhr'],
});

3Verify

Build the extension again and repeat the request.

npm run build

Confirmed by axios.rest

Did this fix it?

How do I stop it coming back?

  • Keep one axios instance per runtime (service worker, page, Node.js) instead of one shared config.
  • In a service worker, call fetch or use the fetch adapter; do not use XMLHttpRequest-based libraries.
  • Do not copy server-side axios settings into browser or extension code.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Web apps

A POST to a Google Apps Script web app returns 405 or a CORS error

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Apps Script web apps run doPost for POST and doGet for GET, and the Apps Script guides describe no other entry points.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.