Keep require() behavior

This will allow to require .js and .json when no extension is given
Also does not swallow potential file parsing errors
This commit is contained in:
Johannes Zellner
2025-01-31 10:43:08 +01:00
parent c28eeaae9a
commit 62a58971bf
+4 -8
View File
@@ -2104,15 +2104,11 @@ function removeIP(socket) {
* @returns
*/
function safeRequire(filePath) {
let data = null;
try {
// Resolve the absolute path of the module
const resolvedPath = require.resolve(filePath);
// Check if the file exists
if (fs.existsSync(resolvedPath)) {
return require(resolvedPath);
}
data = require(filePath);
} catch (error) {
log.error('Module not found', filePath);
log.error(error);
}
return null;
return data;
}