Exception in nodemon killing node referenceerror: primordials is not defined

Developers working with Node.js, have instances encounter errors like “Exception in Nodemon: Killing Node ReferenceError: Primordials is not Defined“.

Which can lead to confusion and impede the development workflow.

This article will examine the underlying reasons behind this exception and provide practical solutions to effectively resolve it.

But before that, let’s understand what is nodemon…

What is Nodemon?

Nodemon, also known as “node monitor,” is a widely used tool in the Node.js community.

It allows for automatic restarting of Node.js applications whenever there are changes made to files within a specific directory.

This convenient feature eliminates the manual task of restarting applications after each modification, which ultimately saves developers time and effort.

What is Exception in nodemon killing node referenceerror: primordials is not defined?

The error message “Exception in nodemon killing node referenceerror: primordials is not defined,” is telling us that something went wrong while using nodemon.

The Nodemon is a helpful tool for automatically restarting a Node.js application whenever we make changes to our files.

In this case, the error is specifically related to a problem with the “primordials” reference.

This could be a module or object that should be available but is not being found.

Additionally, the error often occurs when there is a mismatch between the version of Node.js we’re using and the dependencies installed.

The most common reason for this error is that the project’s dependencies are not compatible with the version of Node.js being used.

It usually happens when the project relies on an older version of a package that depends on a specific feature called “primordial.”

However, this feature was removed in newer versions of Node.js, leading to the error message you encountered.

Example of Exception in nodemon killing node referenceerror

Here’s an example of a program that may encounter the “Exception in nodemon killing node referenceerror: primordials is not defined” error:

const http = require('http');

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello, world!');
});

server.listen(3000, 'localhost', () => {
  console.log('Server is running on port 3000');
});

When you try to run this program using Nodemon, you might encounter the “Exception in nodemon killing node referenceerror: primordials is not defined” error.

This error typically occurs due to conflicts or compatibility issues with the dependencies.

How to fix Exception in nodemon killing node referenceerror: primordials is not defined?

To fix the “Exception in nodemon killing node referenceerror: primordials is not defined” error, you can follow these steps:

  1. Update Node.js and NPM

    Ensure that you have the latest versions of Node.js and NPM installed on your system.

    You can check the versions by running the following commands:

    node –version
    npm –version

    If you have an outdated version, visit the official Node.js website and download the latest stable version.

  2. Clear NPM cache

    Clearing the NPM cache can resolve various dependency-related issues.

    Run the following command to clear the cache:

    npm cache clean –force

  3. Reinstall Nodemon

    Uninstall Nodemon globally from your project and reinstall it using the following commands:

    npm uninstall -g nodemon
    npm install -g nodemon

  4. Delete node_modules folder

    Navigate to your project’s directory and delete the node_modules folder.

    You can use the following command:

    rm -rf node_modules

  5. Reinstall project dependencies

    Run the following command to reinstall the project dependencies:

    npm install

  6. Check package.json

    Verify that your project’s package.json file does not have any conflicting dependencies or errors.
    Ensure that the required packages and their versions are specified correctly.

  7. Try an alternative package manager

    If the error persists, you can try using an alternative package manager such as Yarn instead of NPM.

    Install Yarn globally by running:

    npm install -g yarn

    Then, instead of using npm install, use the following command to install dependencies:

    yarn install

    Yarn often handles dependencies more reliably than NPM and may help resolve the issue.

  8. Update your code

    If you’re using any outdated or deprecated code, make sure to update it to the latest standards.

Anyway besides this error, we also have fixed errors that you can check which might help you when you encounter them.

Conclusion

In conclusion, “Exception in nodemon killing node referenceerror: primordials is not defined” typically occurs when there are compatibility issues or conflicts with dependencies, specifically related to the “primordials” module.

This error often arises when using older versions of Node.js or NPM, or when there are inconsistencies in the project’s dependencies.

I think that’s all for this error. We hope this article has helped fix the issues.

Until next time! 😊

Node.js ReferenceError patterns

Node.js ReferenceErrors usually come from missing require/import statements, ES module vs CommonJS mismatch, or trying to use browser globals (window, document) that do not exist in Node.

Common triggers

  • ES modules vs CommonJS. require is CommonJS; import is ESM. Files ending .mjs or with "type": "module" in package.json use ESM only.
  • Missing global-like modules. fetch was added natively in Node 18. Older Node needs import fetch from 'node-fetch';.
  • Browser globals in Node. window, document, localStorage do not exist. Use Node equivalents or polyfills.
  • __dirname and __filename in ES modules. Not available — derive from import.meta.url.
  • process not defined in ES modules of browser context. Node.js process global is not automatically shimmed in bundlers.

Diagnostic pattern

// BAD — mixing require and ES module context
// package.json has "type": "module"
const fs = require('fs');  // ReferenceError: require is not defined

// GOOD — use ES import
import fs from 'node:fs';
import path from 'node:path';

// __dirname replacement in ES modules
import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

Best practices

  • Pick ESM or CommonJS per project. Not both — Node 20+ handles ESM well.
  • Use node:fs prefix. Explicit built-in modules are clearer.
  • Upgrade to Node 20 LTS. Latest features + long support window.
  • Use TypeScript for larger projects. Catches ReferenceErrors before runtime.

Frequently Asked Questions

What is JavaScript ReferenceError and what causes it?

ReferenceError is raised when JavaScript tries to use a variable that doesn’t exist in the current scope. Common causes: typo in variable name, accessing a variable declared with let/const before its declaration (temporal dead zone), assuming Node.js globals exist in the browser (or vice versa), or import path errors in ES modules.

How do I fix ‘window is not defined’ in Next.js or SSR?

Server-side rendering runs your code on the server where ‘window’ (a browser-only global) doesn’t exist. Fix: gate the code with typeof window !== ‘undefined’ OR move it into a useEffect (which only runs client-side). For Next.js, dynamic import with ssr: false also works.

How do I fix ‘fetch is not defined’ in Node.js?

fetch was browser-only until Node 18. Three fixes: (1) Upgrade to Node 18+. (2) Install node-fetch (npm install node-fetch) and import it. (3) Use axios as a cross-platform alternative. For React Native, use the built-in fetch (it’s a browser-like environment).

What is the temporal dead zone in JavaScript?

The period between when a let/const variable is hoisted to the top of its block and when it’s actually declared. Accessing it during this window throws ReferenceError. Example: console.log(x); let x = 5; throws because x hasn’t been declared yet. With var, this would print undefined instead (var is hoisted with undefined value).

Where can I find more ReferenceError fixes?

Browse the ReferenceError reference hub for 34+ specific JavaScript fixes (Node ESM, SSR, React, browser globals). For JavaScript fundamentals see the JavaScript Tutorial hub.

Glay Eliver


Programmer & Technical Writer at PIES IT Solution

Glay Eliver is a programmer and writer at PIES IT Solution, author of over 600 tutorials at itsourcecode.com. Specializes in JavaScript tutorials, Microsoft Office how-tos (Excel, Word, PowerPoint), and Python error debugging covering ImportError, TypeError, AttributeError, ModuleNotFoundError, and JavaScript ReferenceError. Authored several of the site’s highest-traffic Excel and MS Office reference articles.

Expertise: JavaScript · MS Excel · MS Word · MS PowerPoint · Python · Python ImportError · Python TypeError · Python AttributeError · ModuleNotFoundError · JavaScript ReferenceError · Pygame
 · View all posts by Glay Eliver →

Leave a Comment