Skip to content

Node.js based forum software built for the modern web

chore: up mocha, prevent crash in require.main

Barış Soner Uşaklıa8250d7c01dd
diff --git a/install/package.json b/install/package.json
index 6df46cfaf4..3547260888 100644
--- a/install/package.json
+++ b/install/package.json
@@ -181,7 +181,7 @@
"husky": "8.0.3",
"jsdom": "30.0.1",
"lint-staged": "17.3.0",
- "mocha": "11.8.0",
+ "mocha": "12.0.0",
"mocha-lcov-reporter": "1.3.0",
"mockdate": "3.0.5",
"nyc": "18.0.0",
diff --git a/require-main.js b/require-main.js
index 733a7a7fa4..7cf9fa2fac 100644
--- a/require-main.js
+++ b/require-main.js
@@ -3,14 +3,14 @@
// this forces `require.main.require` to always be relative to this directory
// this allows plugins to use `require.main.require` to reference NodeBB modules
// without worrying about multiple parent modules
-if (require.main !== module) {
+if (require.main && require.main !== module) {
require.main.require = function (path) {
if (process.env.NODE_ENV === 'development') {
const e = (new Error().stack).split('\n')[2].trim();
if (e.includes('nodebb-')) { // only warn nodebb-plugin/theme etc.
const chalk = require('chalk').default;
const warningText = chalk.red(`Warning`);
- console.warn(`${warningText}: require.main.require is going to be deprecated. Please use nodebb.require("${path}") instead.\n${e}\n`);
+ console.warn(`${warningText}: require.main.require is deprecated. Please use nodebb.require("${path}") instead.\n${e}\n`);
}
}
return require(path);