簡體   English   中英

類型錯誤:module.exports 不是 function

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

我的目標是在我的 app.js 中使用 logger.js 我是從教程中輸入的,但我得到的結果與教程不同。

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

當我在控制台中鍵入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默認情況下是 object 並且您尚未將其重新分配給 function 因此您無法像 ZC1C425268E68385D1AB5074C17A9F 那樣使用括號調用它。 您可以將屬性添加到module.exports ,就像通過賦值將它們添加到 JS 中的 object 一樣。

module.exports.log = log;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM