node.js / promises /错误消息:…不是一个函数

我正在尝试运行一个简单的2文件node.js项目。 项目正在运行问题,并显示错误消息“ TypeError:steamBroccoli不是函数”。 我从steamBroccoli()中删除了大括号-它起作用了,该项目顺利运行。 但是我不知道它是如何运行的,也不知道为什么它指出了这个问题,因为steamBroccoli是一个函数。

library.js

let cookBeans = () => {
return new Promise ((resolve, reject) => {
 setTimeout(()=>{
   resolve('beans')
 }, 1000)
})
}

let steamBroccoli = () => {
return new Promise ((resolve, reject) => {
 setTimeout(()=>{
   resolve('broccoli')
 }, 1000)
})
}

let cookRice = () => {
return new Promise ((resolve, reject) => {
 setTimeout(()=>{
   resolve('rice')
 }, 1000)
})
}

let bakeChicken = () => {
return new Promise ((resolve, reject) => {
 setTimeout(()=>{
   resolve('chicken')
 }, 1000)
})
}

module.exports = {cookBeans, steamBroccoli, cookRice, bakeChicken}
let {cookBeans, steamBroccoli, cookRice, bakeChicken} = require('./library.js')

async function serveDinner(){
  const vegetablePromise = steamBroccoli(); // If I remove the braces  - The error disappear and the code works.  
  const starchPromise = cookRice();
  const proteinPromise = bakeChicken();
  const sidePromise = cookBeans();
  console.log(`Dinner is served. We're having ${await vegetablePromise}, ${await starchPromise}, ${await proteinPromise}, and ${await sidePromise}.`)
}
serveDinner();
评论