首页 > 解决方案 > Cloud Functions Node.js Emulator 无法部署功能 - 找不到模块

问题描述

我一直在阅读每篇文章但没有成功。我正在尝试使用 nodejs 模拟器在本地运行我的 Firebase Cloud Functions 代码。我按照官方文档中的步骤进行操作,但在部署函数“helloworld”后出现以下错误(函数部署 helloWorld --trigger-http)

ERROR: Function load error: Code could not be loaded.
ERROR: Does the file exists? Is there a syntax error in your code?
ERROR: Detailed stack trace: internal/modules/cjs/loader.js:584
    throw err;
    ^

Error: Cannot find module 'c:/Users/Ezequiel/Desktop/galum/functions'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at [eval]:1:40
    at Script.runInThisContext (vm.js:119:20)
    at Object.runInThisContext (vm.js:326:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at evalScript (internal/bootstrap/node.js:589:27)

ERROR: Error: Failed to deploy function.
    at exec (c:\Users\Ezequiel\AppData\Roaming\npm\node_modules\@google-cloud\fu
nctions-emulator\src\cli\controller.js:126:22)
    at ChildProcess.exithandler (child_process.js:301:5)
    at ChildProcess.emit (events.js:189:13)
    at maybeClose (internal/child_process.js:970:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)

请注意,我在放置我的 index.js 的项目文件夹中。

标签: firebasegoogle-cloud-firestoregoogle-cloud-functions

解决方案


您应该在您index.js存在的目录中运行部署命令。

在以下页面的情况下,它命名为helloWorld.

https://github.com/GoogleCloudPlatform/cloud-functions-emulator/

.
└── helloWorld
    └── index.js
cd helloWorld
functions-emulator start
functions-emulator deploy helloWorld --trigger-http
functions-emulator call helloWorld
functions-emulator logs read
functions-emulator stop

推荐阅读