Node.js “require” function and parameters

后端 未结 2 1341
耶瑟儿~
耶瑟儿~ 2020-12-12 14:32

When I do:

lib = require(\'lib.js\')(app)

is app actually geting passed in?

in lib.js:

exports = modul         


        
2条回答
  •  既然无缘
    2020-12-12 14:42

    You may have an undefined value that you're trying to pass in.

    Take for instance, requires.js:

    module.exports = exports = function() {
       console.log('arguments: %j\n', arguments);
    };
    

    When you call it correctly, it works:

    node
    > var requires = require('./requires')(0,1,2,3,4,5);
    arguments: {"0":0,"1":1,"2":2,"3":3,"4":4,"5":5}
    

    If you have a syntax error, it fails:

    > var requires = require('./requires')(0,);
    ... var requires = require('./requires')(0,2);
    ... 
    

    If you have an undefined object, it doesn't work:

    > var requires = require('./requires')(0, undefined);
    arguments: {"0":0}
    

    So, I'd first check to see that your object is defined properly (and spelled properly when you pass it in), then check that you don't have syntax errors.

提交回复
热议问题