简体   繁体   English

类型错误:module.exports 不是 function

[英]TypeError: module.exports is not a function

My goal is to use the logger.js inside my app.js I typed this from a tutorial but I have got different results than the tutorial.我的目标是在我的 app.js 中使用 logger.js 我是从教程中输入的,但我得到的结果与教程不同。

-node-tutorial --logger.js --app.js -node-tutorial --logger.js --app.js

When I type node app.js in the console, I get this:当我在控制台中键入node app.js时,我得到了这个:

timbliefert@Tims-Air node-tutorial % node app.js
/Users/timbliefert/Developer/node-tutorial/logger.js:9
module.exports(log) = log;
       ^

TypeError: module.exports is not a function
    at Object.<anonymous> (/Users/timbliefert/Developer/node-tutorial/logger.js:9:8)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/Users/timbliefert/Developer/node-tutorial/app.js:2:14)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)```

module.exports is an object by default and you haven't reassigned it to a function so you're not able to invoke it with parenthesis like a function. module.exports默认情况下是 object 并且您尚未将其重新分配给 function 因此您无法像 ZC1C425268E68385D1AB5074C17A9F 那样使用括号调用它。 You can add properties to module.exports exactly like how you'd add them to an object in JS through assignment.您可以将属性添加到module.exports ,就像通过赋值将它们添加到 JS 中的 object 一样。

module.exports.log = log;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM