Uncaught referenceerror exports is not defined
In this article, we’ll be exploring one specific error called the Uncaught referenceerror exports is not defined error and diving into its details. As a JavaScript developer, it’s completely normal …
itsourcecode.com hosts 34+ documented fixes for JavaScript ReferenceError messages: the error class raised when JavaScript tries to access a variable, function, or global that doesn’t exist in the current scope. Most ReferenceErrors come from SSR vs browser context mismatches (window, document, navigator on server), ES Module vs CommonJS confusion (__dirname, require, module), Node.js version migrations (primordials, fetch), or library loading order (React, Jest, Google Maps). Browse the fixes below.
What is a JavaScript ReferenceError?
A ReferenceError is raised when JavaScript tries to read a variable or identifier that hasn’t been declared in any reachable scope. It’s distinct from TypeError (the value exists but has the wrong type) and from SyntaxError (the code couldn’t be parsed). Most ReferenceErrors are “X is not defined”, and the fix usually involves either declaring/importing X, or running the code in the right environment where X already exists as a global.
How to debug any ReferenceError in 4 steps
Read the missing identifier in the message. ReferenceError: X is not defined tells you exactly what’s missing.
Determine the runtime context. Browser globals (window, document, navigator, fetch in older Node) don’t exist server-side. Node-only globals (process, __dirname, require) don’t exist in browsers OR in Node ES modules. Frameworks like Next.js/Nuxt/Remix run code in BOTH contexts.
Check the module type. If you see __dirname is not defined in ES module scope, you’re in an ESM file. Use import.meta.url + fileURLToPath instead. If require is not defined, same issue, opposite direction.
Check load order. If the missing name is a library global ($, React, google, jest), the library hasn’t loaded yet. Check script tag order, or import explicitly.
Featured ReferenceError fixes by category
🌐 Browser globals on server (SSR / Node)
The single most common ReferenceError class for modern web devs. Server has no window, document, or navigator.
Uncaught ReferenceError: X is not defined
ReferenceError: navigator is not defined
Uncaught ReferenceError: function is not defined
📦 ES Modules: Node.js
Node 12+ supports ES modules. Switching from CommonJS to ESM breaks names that ESM doesn’t expose globally.
__dirname is not defined in ES module scope
exports is not defined in ES module scope
Uncaught ReferenceError: exports is not defined
Uncaught ReferenceError: global is not defined (browser)
Uncaught ReferenceError: process is not defined
ReferenceError: Buffer is not defined (browser bundlers)
ReferenceError: globalThis is not defined
⚛️ React / Next.js / build tools
ReferenceError: React is not defined (JSX without import)
ReferenceError: Jest is not defined, 2026 Guide
ReferenceError: primordials is not defined
Exception in nodemon: primordials is not defined
📡 Network / Request globals
ReferenceError: request is not defined
ReferenceError: response is not defined
ReferenceError: File is not defined (Node before File API)
🗺️ Library/CDN globals (Google Maps, etc.)
Uncaught ReferenceError: google is not defined (Maps API)
Related error categories
ReferenceError is one of 10 hubs in our Python & JavaScript error reference cluster, 980+ documented fixes total:
TypeError Reference, 220+ Python & JS TypeError fixes
ModuleNotFoundError Reference, 198+ Python import errors
AttributeError Reference, 173+ “object has no attribute X” fixes
ValueError Reference, 100+ pandas/NumPy/sklearn fixes
ImportError Reference, 67+ “cannot import name X from Y” fixes
NameError Reference, 49+ Python “name X is not defined” fixes
RuntimeError Reference, 49+ PyTorch/CUDA/async runtime errors
SyntaxError Reference, 48+ Python & JavaScript syntax errors
HTTP Error Reference, 35+ HTTP status code fixes (4xx, 5xx)
Python Tutorial, beginner-to-intermediate Python lessons
About this ReferenceError reference
Built since 2015 by PIES Information Technology Solutions, Binalbagan, Negros Occidental, Philippines. Every post comes from a real error encountered in production code. Used by 12,000+ developers monthly.
In this article, we’ll be exploring one specific error called the Uncaught referenceerror exports is not defined error and diving into its details. As a JavaScript developer, it’s completely normal …
In this article, we’ll be exploring one specific error called the “uncaught referenceerror: require is not defined” error and diving into its details. As a JavaScript developer, it’s completely normal …
The error message “uncaught referenceerror: $ is not defined” is frequently encountered by developers in JavaScript, causing confusion and frustration. It is essential for creating reliable and bug-free web applications …
If you’ve seen the error “ReferenceError jest is not defined” while using Jest. Indeed, it can be really frustrating, especially when you’re trying to run tests or use Jest’s powerful …
If you have come across this Referenceerror: primordials is not defined error while working with Node.js or any associated frameworks, you have come to the right place. In this guide, …
In the realm of programming, errors are commonplace. One error that can be particularly frustrating for developers is the “Uncaught ReferenceError: function is not defined.” This error arises when a …
The JavaScript error message “ReferenceError: React is not defined” commonly appears when the React library is not correctly imported or referenced in a project. Which React is a JavaScript library …
JavaScript developers often encounter a common error known as “Uncaught ReferenceError: Google is not defined.” This error can be particularly frustrating, especially when you depend on Google services in your …