Node returns undefined required

I have an ErrorHandler class in my node code that handles all errors that occur.

Each error has its own class. All classes are placed in separate files, so the folder structure:

  • ErrorHandler.js
    • Error110.js
    • Error131.js
    • ...

ErrorHandler requires each of these files (along with some others)

var serverErrorCodes        = require('../../config/ErrorCodesConfig').server,
clientErrorCodes            = require('../../config/ErrorCodesConfig').client,
Error110                    = require('./errors/Error110').Error110,
Error131                    = require('./errors/Error131').Error131,
Error132                    = require('./errors/Error132').Error132,
Error133                    = require('./errors/Error133').Error133,
Error150                    = require('./errors/Error150').Error150;

When checking in node -debugger at runtime, the result ist is required:

Closure:
  Error110: function Error110(params)
  Error131: function Error131(params)
  Error132: undefined
  Error133: undefined
  Error150: function Error150(messageObject, callback)

Error 132 and Error133 are not available after the request, while others are excellent.

I read that this happens if you have the required loop, and therefore the required module (A) requires module (B), which again requires the A. node module, and then completes this cycle, returning undefinedafter the first one requires. This is not true.

, , - node " " , , "" . . , .

, .

, Worp

1:
: " !
, , - . , . , , , util , , .

+4
2

, ? console.log(require ('./errors/Error132))? Error132 Error133?

-1

, module.exports undefined , . .

, , - .

.

- node, " "

require . .

, A B, , , A, A undefined B. , .

+11

All Articles