Fix 'fetch is not defined' Error in Excel Office Add-ins
Question details
Developers need to resolve a 'fetch is not defined' JavaScript error encountered in taskpane.js while building an Excel Office Add-in.

- Product
- Microsoft Excel Office Add-ins
- Device & OS
- not provided
- Scenario
- Developing an Office Add-in using Microsoft's guidance for single sign-on (SSO) or nested app authentication, resulting in runtime execution failures.
- Observed behavior
- The add-in fails to execute network requests, and the developer console throws a 'fetch is not defined' error because the runtime environment does not natively support the Fetch API.
Ensure you know which webview engine (such as Edge WebView2 or Internet Explorer 11) your specific version of Microsoft Office relies on to render add-ins, as this dictates your JavaScript API support.
Verify Browser Environment and Add Fetch Polyfills
Use a JavaScript polyfill to add Fetch API support for older Office embedded browser runtimes that do not natively support it.
Microsoft Office Add-ins are rendered using an embedded web browser control. While modern Office setups use Chromium-based WebView2, older installations use Trident (Internet Explorer 11), which lacks native support for the Fetch API. Injecting a polyfill ensures cross-version compatibility.
Open your terminal, navigate to your Office Add-in project folder, and run a package manager command like 'npm install whatwg-fetch' to download the polyfill.
Open your 'taskpane.js' file or the main JavaScript entry point of your add-in, and add 'import "whatwg-fetch";' at the very top of the file.
If you are using Webpack or Rollup, ensure your configuration is set to include imported polyfills in the final output bundle targeted for the browser.
Run 'npm start' to sideload the add-in into the Excel desktop application and verify that the authentication network requests now succeed without the error.

Consult the Office Development Community for Authentication Errors
If the error persists exclusively during single sign-on (SSO) or nested app authentication flows, seek targeted help from Microsoft's developer forums.
Looking for a Developer-Friendly, Lightweight Office Suite?
If complex add-in configurations and legacy runtime compatibility issues in Microsoft Office are slowing down your workflow, consider trying WPS Office. It delivers a fast, stable, and highly compatible environment for all your spreadsheet tasks without the heavy overhead.
- 1. Download the installer: Visit the official WPS Office website and download the free installer for your operating system.
- 2. Install WPS Office: Run the setup file and follow the quick on-screen instructions to complete the installation.
- 3. Open your files instantly: Launch WPS Spreadsheet and directly open your existing .xlsx files without worrying about formatting loss.

Frequently Asked Questions
Why does 'fetch is not defined' happen in desktop Excel but not on the web?
Excel on the web runs inside your standard modern web browser (like Chrome or Edge), which natively supports the Fetch API. The desktop version of Excel may rely on an older embedded web control, such as Internet Explorer 11, which does not support modern JavaScript APIs without polyfills.
How do I check which browser engine my Office Add-in is using?
The browser engine depends on your Windows version and Office build. You can determine this by opening your add-in's developer tools and checking the 'navigator.userAgent' string in the console. Modern Microsoft 365 environments generally use Edge WebView2 (Chromium), while older retail versions fall back to Trident.
Can I use Axios instead of Fetch to fix this error?
Yes. Axios is a popular HTTP client that uses 'XMLHttpRequest' under the hood rather than the Fetch API. Because 'XMLHttpRequest' is supported even in older Internet Explorer 11 runtimes, replacing fetch with Axios will bypass the 'fetch is not defined' error completely.




