Cardinal Review

Node.js module 'module' not found

critical node

In the console

Cannot find module 'module'
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'module'
MODULE_NOT_FOUND

Node.js could not find a module. If the name is a package, it was never installed (node_modules is missing or incomplete). If it is a path, the main file or an import points to a file that does not exist.

How to fix it

  1. If it is a package: make sure package.json lists it, then restart so the egg runs npm install (or add it to the 'additional node packages' startup variable).
  2. If node_modules was uploaded from Windows or macOS, delete it and let the server reinstall dependencies on Linux.
  3. If it is a path (starts with ./ or /home/container), check the main file startup variable and the import path, including capitalisation.

require() used on an ES module

error node

In the console

ERR_REQUIRE_ESM
require() of ES Module

The code uses require() for a package that is now published as an ES module only (common after major upgrades of packages such as node-fetch, chalk or got).

How to fix it

  1. Pin the package to its last CommonJS version in package.json (for example node-fetch@2 or chalk@4), or
  2. Switch your code to ES modules ("type": "module" in package.json and import syntax), or use a dynamic import().

import statement used in a CommonJS file

error node

In the console

Cannot use import statement outside a module

The file uses import/export syntax but Node.js treats it as CommonJS.

How to fix it

  1. Add "type": "module" to package.json, or rename the file to .mjs, or
  2. Change import to require() if the project is meant to be CommonJS.

Node.js ran out of heap memory

critical node

In the console

JavaScript heap out of memory
Reached heap limit Allocation failed
Ineffective mark-compacts near heap limit

V8 hit its heap limit. Either the app needs more than the default limit, or it keeps data it never frees (caches without limits, growing arrays, listeners added repeatedly).

How to fix it

  1. Raise the limit with --max-old-space-size (in MB, for example node --max-old-space-size=1536 index.js), keeping it below the server's memory limit.
  2. Watch memory in the Performance tab: a steady climb is a leak; look at caches and event listeners.
  3. For Discord bots, limit cache sizes (makeCache / sweepers in discord.js).

Unhandled promise rejection crashed the app

error node

In the console

UnhandledPromiseRejection
Unhandled promise rejection
triggerUncaughtException

An async operation failed and nothing caught the error. Since Node.js 15 this terminates the process.

How to fix it

  1. Read the error printed above for the real cause (network, permissions, invalid data).
  2. Wrap the failing await in try/catch, or add .catch() to the promise.
  3. Add a process.on('unhandledRejection') handler that logs errors so one failure does not take the whole app down.

JavaScript syntax error

critical node

In the console

SyntaxError: message

Node.js could not parse a file: message. Either the file has a typo, or it uses syntax that this Node.js version does not support yet (for example ??=, ?. or top-level await on old versions).

How to fix it

  1. Open the file and line shown above the error and fix the syntax.
  2. If the code is from a package or tutorial, check its required Node.js version and pick a matching Docker image on the Startup page.

Package requires a different Node.js version

error node

In the console

The engine "node" is incompatible with this module
Unsupported engine
requires Node version

A package declares that it needs another Node.js version (see the message).

How to fix it

  1. Choose a Docker image with a supported Node.js version on the Startup page (current LTS versions are the safest choice).
  2. Or install an older version of the package that supports your Node.js version.

package.json not found

critical node

In the console

npm ERR! ENOENT … package.json
Could not read package.json
no such file or directory, open ' … package.json'

npm ran in a folder without package.json, so dependencies cannot be installed. The project files were uploaded into a subfolder, or not uploaded at all.

How to fix it

  1. Make sure package.json is in the server's root folder (/home/container), not inside a subfolder from an archive.
  2. If you use git deployment, check the repository and branch startup variables.

npm install failed (code)

error node

In the console

npm ERR! code code
npm ERR! ERESOLVE

Installing dependencies failed. ERESOLVE means conflicting peer dependencies, ETARGET/E404 a version that does not exist, ECONNRESET/ETIMEDOUT network trouble, EACCES permissions.

How to fix it

  1. Read the npm error lines below this one for the package that failed.
  2. For ERESOLVE, align the conflicting versions in package.json (or use --legacy-peer-deps if you accept the risk).
  3. Delete node_modules and package-lock.json if they came from another machine, then restart.

Native module failed to build

error node

In the console

gyp ERR!
node-pre-gyp ERR!
was compiled against a different Node.js version using NODE_MODULE_VERSION built

A package with native code (sqlite3, bcrypt, canvas, sharp...) could not download a prebuilt binary and could not compile one, or it was built for another Node.js version.

How to fix it

  1. Delete node_modules and reinstall after changing Node.js versions.
  2. Switch to a pure-JavaScript alternative where possible (bcryptjs instead of bcrypt, better-sqlite3 prebuilds).
  3. Use a Node.js version for which the package publishes prebuilt binaries.

Discord bot token is invalid

critical node python discord

In the console

An invalid token was provided
TokenInvalid
TOKEN_INVALID
LoginFailure: Improper token has been passed

Discord rejected the bot token. It was mistyped, regenerated in the Developer Portal, or it is a user/client secret instead of the bot token.

How to fix it

  1. Open the Discord Developer Portal > your application > Bot, and reset the token.
  2. Paste the new token into the bot's config or startup variable without quotes or spaces.
  3. Never share the token; if it was posted anywhere public, reset it again.

Bot uses privileged intents that are not enabled

critical node python discord

In the console

Used disallowed intents
DisallowedIntents
PrivilegedIntentsRequired

The bot asks for privileged gateway intents (Message Content, Server Members or Presence) that are switched off for the application.

How to fix it

  1. Developer Portal > your application > Bot > Privileged Gateway Intents: enable the ones the bot requests.
  2. Or remove those intents from the bot's code if it does not need them.
  3. Bots in 100+ servers need Discord's approval for privileged intents.

Bot is missing Discord permissions

error node python discord

In the console

DiscordAPIError[50013]
error code: 50013
DiscordAPIError: Missing Permissions
DiscordAPIError[50001]: Missing Access

Discord refused an action because the bot's role lacks a permission, or its role is below the role/user it tries to manage, or it cannot see the channel.

How to fix it

  1. Give the bot's role the permission it needs in Server Settings > Roles, or in the channel's permission overrides.
  2. Move the bot's role above the roles it should manage.
  3. Re-invite the bot with the right permission scope if needed.

Rate limited by an API

warning node python discord

In the console

429 Too Many Requests
You are being rate limited
RateLimitError
We are being rate limited

The app sent too many requests and the API (often Discord) is making it wait. Repeated global rate limits can get the bot or IP temporarily banned.

How to fix it

  1. Avoid loops that send messages, edit roles or fetch members repeatedly.
  2. Cache data instead of re-fetching it, and add delays to bulk actions.
  3. Check whether the bot restarts in a loop and logs in again each time (each login counts).

Discord bot replied to an interaction too late

warning discord

In the console

DiscordAPIError[10062]
(error code: 10062)
Unknown interaction

The bot answered a slash command, button or menu after Discord's 3-second window (or answered one it had already lost), so Discord rejected it and users saw 'The application did not respond'. Slow code before the reply, a busy or overloaded host, or two copies of the bot running with the same token are the usual causes.

How to fix it

  1. Call deferReply() (discord.js) or interaction.response.defer() (discord.py) straight away, then do the slow work and use editReply/followup.
  2. Make sure only one copy of the bot is running: a second instance on another host answers first and the other gets this error.
  3. If it happens under load, check the server's CPU usage and the bot's event loop for blocking work.

Discord bot replied to the same interaction twice

warning discord

In the console

DiscordAPIError[40060]
(error code: 40060)
Interaction has already been acknowledged

The bot tried to reply to an interaction it had already replied to or deferred. It is a bug in the bot's code (two handlers for the same command, or reply() after deferReply()), or two copies of the bot running at once.

How to fix it

  1. After deferReply() or a first reply, use editReply() or followUp() instead of reply().
  2. Check that the command is not registered or handled twice.
  3. Make sure only one copy of the bot runs with this token.

Node.js is too old for fetch()

error node

In the console

ReferenceError: fetch is not defined

The code calls fetch(), which only exists built in from Node.js 18. The server's Docker image runs an older Node.js.

How to fix it

  1. In the server's Startup tab, pick a Docker image with Node.js 18 or newer (20 or 22 recommended) and restart.
  2. If you must stay on old Node.js, install node-fetch and import it, but upgrading is the better fix.

Not sure which one you have?

Paste your log into the live demo, or install Cardinal Review Lite and it will point at the line for you. Lite is free.