Node "ReferenceError: X is not defined" in CI - Track Down the Missing Symbol
ReferenceError means your code read an identifier that was never declared in scope. The crash point names the symbol Node could not find.
What this error means
A node process throws ReferenceError: <name> is not defined and exits non-zero. The name may be a variable, an import you forgot, or a browser-only global.
node
/home/runner/work/app/app/src/index.js:12
console.log(API_BASE);
^
ReferenceError: API_BASE is not defined
at Object.<anonymous> (/home/runner/work/app/app/src/index.js:12:13)Common causes
A missing import or require
The symbol is exported elsewhere but never imported into this file, so it is undeclared at runtime.
A browser-only global used under Node
Code assumes window, document, or localStorage, which do not exist in the Node CI runtime.
How to fix it
Import or declare the symbol
- Find where the identifier is defined or exported.
- Add the import, or declare the variable before use.
- Re-run to confirm the reference resolves.
JavaScript
import { API_BASE } from './config.js';Guard browser-only globals
- Wrap browser globals in a typeof check so Node does not evaluate them.
- Provide a Node fallback where one is needed.
JavaScript
const hasWindow = typeof window !== 'undefined';How to prevent it
- Enable a no-undef lint rule, separate browser and Node entry points, and run the same code path locally that CI runs so missing references surface before merge.
Related guides
Node "TypeError: X is not a function" in CI - Fix the Bad CallFix the Node.js "TypeError: X is not a function" in CI by correcting a bad import shape, a missing method, or…
Node "Cannot read properties of undefined (reading X)" in CI - Fix the Null AccessFix the Node.js "Cannot read properties of undefined (reading X)" TypeError in CI by guarding the access or e…
Node "Error: Cannot find module 'X'" in CI - Fix Module ResolutionFix the Node.js "Error: Cannot find module" crash in CI by correcting the path, extension, or build output th…