Cloud Functions Node.js模拟器无法部署功能-无法找到模块

时间:2019-04-07 22:37:38

标签: firebase google-cloud-firestore google-cloud-functions

我一直在阅读每篇文章,但均未获得成功。我正在尝试使用nodejs模拟器在本地运行Firebase Cloud Functions代码。我按照官方docs的步骤进行操作,但是在部署函数“ 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的项目文件夹中。

1 个答案:

答案 0 :(得分:0)

You should run deploy command in directory that your index.js exists.

In case of the following page, it named 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