> firebase --version
3.17.1
> node --version
v6.12.3
> npm --version
5.6.0
> git clone https://github.com/firebase/functions-samples.git
> cd functions-samples/authenticated-json-api/functions/
> npm install
> [email protected] install /Users/karl/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/grpc
> node-pre-gyp install --fallback-to-build --library=static_library
[grpc] Success: "/Users/karl/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/grpc/src/node/extension_binary/node-v48-darwin-x64-unknown/grpc_node.node" is installed via remote
> [email protected] postinstall /Users/karl/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/protobufjs
> node scripts/postinstall
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] requires a peer of firebase-admin@~4.2.1 but none is installed. You must install peer dependencies yourself.
added 354 packages in 11.832s
> firebase use my-project
Now using project my-project
> firebase serve --only functions
=== Serving from '/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api'...
i functions: Preparing to emulate functions.
⚠ functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
⚠ functions: Error from emulator. FirebaseError: Error occurred while parsing your function triggers. Please ensure you have the latest firebase-functions SDK by running "npm i --save firebase-functions@latest" inside your functions folder.
Error: Firebase config variables are not available. Please use the latest version of the Firebase CLI to deploy this function.
at init (/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/firebase-functions/lib/config.js:51:15)
at Object.config (/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/firebase-functions/lib/config.js:29:9)
at Object.<anonymous> (/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/index.js:27:31)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
> firebase serve --only functions --debug
[2018-01-19T03:30:49.455Z] ----------------------------------------------------------------------
[2018-01-19T03:30:49.459Z] Command: /usr/local/Cellar/node@6/6.12.3/bin/node /usr/local/bin/firebase serve --only functions --debug
[2018-01-19T03:30:49.460Z] CLI Version: 3.17.1
[2018-01-19T03:30:49.460Z] Platform: darwin
[2018-01-19T03:30:49.460Z] Node Version: v6.12.3
[2018-01-19T03:30:49.460Z] Time: Thu Jan 18 2018 22:30:49 GMT-0500 (EST)
[2018-01-19T03:30:49.461Z] ----------------------------------------------------------------------
[2018-01-19T03:30:49.476Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2018-01-19T03:30:49.476Z] > authorizing via signed-in user
[2018-01-19T03:30:49.479Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/projects/my-project
Thu Jan 18 2018 22:30:49 GMT-0500 (EST)
[2018-01-19T03:30:49.855Z] <<< HTTP RESPONSE 200 server=nginx, date=Fri, 19 Jan 2018 03:30:49 GMT, content-type=application/json; charset=utf-8, content-length=126, connection=close, x-content-type-options=nosniff, strict-transport-security=max-age=31536000; includeSubdomains, cache-control=no-cache, no-store
[2018-01-19T03:30:49.856Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/database/my-project/tokens
Thu Jan 18 2018 22:30:49 GMT-0500 (EST)
[2018-01-19T03:30:50.482Z] <<< HTTP RESPONSE 200 server=nginx, date=Fri, 19 Jan 2018 03:30:50 GMT, content-type=application/json; charset=utf-8, content-length=267, connection=close, x-content-type-options=nosniff, strict-transport-security=max-age=31536000; includeSubdomains, cache-control=no-cache, no-store
=== Serving from '/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api'...
i functions: Preparing to emulate functions.
[2018-01-19T03:30:51.081Z] Fetching environment
[2018-01-19T03:30:51.082Z] >>> HTTP REQUEST GET https://appengine.googleapis.com/v1/apps/my-project
Thu Jan 18 2018 22:30:51 GMT-0500 (EST)
[2018-01-19T03:30:51.083Z] >>> HTTP REQUEST GET https://apikeys.googleapis.com/v1/projects/my-project/apiKeys
Thu Jan 18 2018 22:30:51 GMT-0500 (EST)
[2018-01-19T03:30:51.569Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Fri, 19 Jan 2018 03:30:51 GMT, server=ESF, cache-control=private, x-xss-protection=1; mode=block, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35", accept-ranges=none, connection=close
[2018-01-19T03:30:51.663Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Fri, 19 Jan 2018 03:30:51 GMT, server=ESF, cache-control=private, x-xss-protection=1; mode=block, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35", accept-ranges=none, connection=close
[2018-01-19T03:30:51.664Z] Starting @google-cloud/functions-emulator
[2018-01-19T03:30:53.220Z] Parsing function triggers
⚠ functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
⚠ functions: Error from emulator. FirebaseError: Error occurred while parsing your function triggers. Please ensure you have the latest firebase-functions SDK by running "npm i --save firebase-functions@latest" inside your functions folder.
Error: Firebase config variables are not available. Please use the latest version of the Firebase CLI to deploy this function.
at init (/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/firebase-functions/lib/config.js:51:15)
at Object.config (/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/firebase-functions/lib/config.js:29:9)
at Object.<anonymous> (/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/index.js:27:31)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
这很奇怪,因为在其他项目中, firebase serve --only functions
冻结了,我尝试了一堆其他示例。 它对他们中的任何一个都不起作用。
它甚至不适用于我已经部署的功能。
尝试从函数目录中运行npm run serve
而不是firebase serve --only functions
,这可能会或可能不会起作用,具体取决于您的 package.json 文件的配置方式。
不幸的是,我没有为此配置 package.json。
> npm run serve
npm ERR! Darwin 17.3.0
npm ERR! argv "/Users/alchemist/.nvm/versions/node/v6.11.5/bin/node" "/Users/karl/.nvm/versions/node/v6.11.5/bin/npm" "run" "serve"
npm ERR! node v6.11.5
npm ERR! npm v3.10.10
npm ERR! missing script: serve
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/npm-debug.log
你能给我指一个吗?
这就是我的新firebase init
后的样子: https ://gist.github.com/dylanjmcdonald/6c033b476e863efaea3eccc0b3137772
我已经设法通过将firebase-tools
降级到 3.16.0 来解决这个错误,因为错误是在我更新到 3.17.1 之后开始的
我第一次在我的 CI 运行程序中偶然发现了这个错误,因为我正在安装最新版本的firebase-tools
进行部署。 一夜之间,我的部署停止工作。 在我升级firebase-admin
和firebase-functions
后,他们又开始工作了。
但后来我的本地环境停止工作。 我仍然可以部署,但无法提供功能。 尝试卸载firebase-tools
并重新安装...以及我能想到的所有变体(清理缓存、使用最新的 NPM、使用 6.11.5、使用 Yarn 等)。 没有运气。
最后,我决定将所有内容回滚到之前工作的版本,并冻结我的 CI 脚本中使用的版本(而不是使用最新的),现在两个环境都可以正常工作。
几个月前,我已经看到了这个问题的不同变体以及不同的可能解决方案。 也许这是一种回归? 一些晦涩的潜在问题?
顺便说一句:我在本地运行 macOS High Sierra 10.13.2 和node:latest Docker image for my CI runner on GitLab,如果有帮助的话。
PS:根据我的经验, npm run dev
在内部运行firebase serve --only functions
。
@rafasoares :谢谢,可以确认降级到 3.16.0 修复了错误!
npm install -g [email protected]
我也在使用 macOS High Sierra 10.13.2,但我使用的是通过nvm
安装的节点 v6.11.5。
@The-Alchemist 很高兴我能帮上忙。
我已经尝试过通过 brew (9.x) 安装的最新节点和通过 nvm 安装的 6.11.5。 它以前在最新的节点上工作(尽管有 GCP 节点版本警告)。
大家好,最新的firebase-tools(3.17.1)也需要最新的firebase-functions SDK,所以解决问题的更好方法是在functions文件夹中运行“npm i --save firebase-functions@latest ”如错误消息所示,在部署或服务之前。
@laurenzlong你看过我上面的评论了吗? 这是我尝试的第一件事。 之后,我能够firebase deploy --only functions
,但不能firebase serve --only functions
。
我已经尝试了各种我能想出的清理策略。 我什至删除了我的工作副本,并从头开始从 Git 中提取所有内容。
@rafasoares抱歉,我错过了那部分。 我现在会调查一下。
惊人的! 谢谢!
v3.17.2 现已发布,应该已经解决了这个问题,如果没有,请告诉我。 感谢您的报告!
刚刚尝试了 v3.17.2,为我工作!
它对我不起作用。 我设法使它在一个空白项目上工作,但无法使我当前的项目工作。
于是我去挖了。 两者有什么区别?
我能够查明问题所在。 当我添加这段代码时它会中断:
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase); // <-- Specifically, this line
如果我删除初始化位,我可以提供这些功能。 但是,我不能使用 Firestore。
更新:如果我用以下 JSON 替换functions.config().firebase
调用,它可以工作:
{
databaseURL: 'https://[PROJECT_NAME].firebaseio.com',
storageBucket: '[PROJECT_NAME].appspot.com',
apiKey: '[API KEY]',
authDomain: '[PROJECT_NAME].firebaseapp.com',
projectId: '[PROJECT_NAME]',
credential: admin.credential.applicationDefault()
}
使用[email protected]
functions.config().firebase
的输出(我从文档中获得的credential
位除外。
不过,我还没有尝试使用此代码进行部署。
@rafasoares我降级了 google-cloud/functions-emulator 依赖项,这就是区别。 尝试“npm uninstall -g firebase-tools & npm i -g firebase-tools”。 根据您拥有的 npm 版本,有时它不会降级依赖项,除非您先进行卸载。
@rafasoares好像我的 semver 版本控制错误,我想我在 #618 中修复了它,你可以尝试使用那个分支吗?
npm install -g https://github.com/firebase/firebase-tools.git#laurenzlong -patch-1
@laurenzlong
好像我的 semver 版本控制错误,我想我在 #618 中修复了它,你可以尝试使用那个分支吗?
我遇到了与@rafasoares相同的问题,我尝试npm install -g https://github.com/firebase/firebase-tools.git#laurenzlong-patch-1
,但问题仍然存在。
通过npm install -g [email protected]
,问题得到解决。
对不起,我一直在玩 Yarn 和 NPM 试图让他们下载正确的版本,我可能搞砸了我的环境哈哈。
但是,是的, https://github.com/firebase/firebase-tools.git#laurenzlong -patch-1 仍然给我错误,即使@google-cloud/[email protected]
是已安装的版本。
@mono0926 @rafasoares这个怎么样?
npm install -g https://github.com/firebase/firebase-tools.git#ll -fixemu
感谢您的耐心和帮助!
npm uninstall -g firebase-tools && npm install -g https://github.com/firebase/firebase-tools.git#ll-fixemu
怎么样
@laurenzlong
怎么样 npm 卸载 -g firebase-tools && npm install -g https://github.com/firebase/firebase-tools.git#ll -fixemu
我已经试过了。
显然https://github.com/firebase/firebase-tools.git#ll -fixemu 为我修复了它。
$ yarn global remove firebase-tools
yarn global v1.3.2
[1/2] Removing module firebase-tools...
[2/2] Regenerating lockfile and installing missing dependencies...
success Uninstalled packages.
✨ Done in 3.91s.
$ yarn global add https://github.com/firebase/firebase-tools.git\#ll-fixemu
yarn global v1.3.2
[1/4] 🔍 Resolving packages...
warning https://github.com/firebase/firebase-tools.git#ll-fixemu > universal-analytics > [email protected]: Use uuid module instead
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
[4/4] 📃 Building fresh packages...
success Installed "[email protected]" with binaries:
- firebase
✨ Done in 11.73s.
$ firebase --version
3.17.2
$ firebase serve --only functions
=== Serving from '/Users/[USERNAME]/dev/projects/[PROJECT NAME]'...
i functions: Preparing to emulate functions.
✔ functions: createUrl: http://localhost:5000/[PROJECT NAME]/us-central1/createUrl
✔ functions: getUrl: http://localhost:5000[PROJECT NAME]us-central1/getUrl
我目前正在使用节点 v6.11.5。 @mono0926也许这与它有关?
@rafasoares
我目前正在使用节点 v6.11.5。 @mono0926也许这与它有关?
我正在使用相同版本的节点🤔
@mono0926是的,我只是在猜测。 我刚刚尝试使用最新的并且它有效。
尝试彻底清理全局依赖项和缓存清理(另外,尝试重建项目的本地依赖项)。 我今天在尝试解决这个问题时已经做了几次,也许它有所帮助。
@rachelmyers @laurenzlong
在尝试npm install -g https://github.com/firebase/firebase-tools.git#ll-fixemu
之后,我注意到错误详细信息发生了变化。
而且,错误发生在我的代码中,我对其进行了修改,然后错误解决了👍
如果我使用[email protected]
,则在不修改我的代码的情况下不会发生错误。
所以,我稍后会告诉你,我调查了问题的细节。
@mono0926您介意与我们分享您在代码中所做的更改吗? 是否与 Firebase 有关?
@rachelmyers @laurenzlong
我对此进行了调查,并弄清楚了这一点。
有了这段代码,
import * as functions from 'firebase-functions';
import * as util from 'util';
console.error(`environment: ${util.inspect(functions.config().environment.project_id)}`);
发生错误:
TypeError: Cannot read property 'project_id' of undefined
但是有了这段代码,
import * as functions from 'firebase-functions';
import * as util from 'util';
console.error(`environment: ${util.inspect(functions.config().environment)}`);
打印此日志:
info: environment: { project_id: 'development' }
为什么我无法访问最新版本的functions.config().environment
project_id
的 project_id?
我能够在 [email protected] 下访问project_id
functions.config().environment
的[email protected]
。
我知道这是这个问题的另一个问题。
您介意与我们分享您在代码中所做的更改吗? 是否与 Firebase 有关?
我通过临时硬编码project_id
值来解决这个问题,所以我希望你解决这个问题。
当我部署这些功能时,问题不会发生。
@The-Alchemist 我也确认一下:降级到 3.16.0 修复了错误!
npm install -g [email protected]
我也在使用 macOS High Sierra 10.13.2 和由其安装程序安装的节点 v8.9.4,具有固定权限: https://docs.npmjs.com/getting-started/fixing-npm-permissions。
在 Windows 上使用[email protected]没有问题。
我得到:
+ [email protected]
updated 1 package in 50.957s
(xenial)marcus<strong i="6">@localhost</strong>:~/app$ firebase serve --only functions
=== Serving from '/home/marcus/app'...
⚠ functions: Cannot start emulator. Error: Cannot find module '/usr/lib/node_modules/firebase-tools/node_modules/grpc/src/node/extension_binary/grpc_node.node'
马库斯: --only functions
(复数)
2018 年 1 月 20 日星期六下午 12:44 Marcus Hitchins [email protected]
写道:
我得到:
- [email protected]
在 50.957 秒内更新了 1 个包
(xenial) marcus@localhost :~/app$ firebase serve --only 功能=== 从“/home/marcus/app”服务...
错误:无法理解要部署的目标。 如果您使用了 --only 或 --except 标志,请检查您是否指定了有效的目标。 否则,请检查您的 firebase.json 以确保您的项目已针对所需功能进行了初始化。
—
您收到此消息是因为您订阅了此线程。
直接回复此邮件,在 GitHub 上查看
https://github.com/firebase/firebase-tools/issues/609#issuecomment-359200751 ,
或使线程静音
https://github.com/notifications/unsubscribe-auth/AAAD_tJH6ez89mjEZVdJbPVMDqeKym76ks5tMlAQgaJpZM4Rj8M0
.
@mono0926我们从不支持模拟器内部的自定义配置值,您需要在您的函数文件夹中运行“firebase functions:config:get > .runtimeconfig.json”,以便将变量存储在 .runtimeconfig.json 中并且可以通过模拟器。
@marcus7777我认为这是一个单独的问题,在https://github.com/firebase/firebase-tools/issues/442中捕获
我现在关闭这个问题,因为最初报告的错误在 v.3.17.3 中得到修复
令人惊讶的是,这件事处理得如此之快。 很棒的工作@laurenzlong。 👏
@laurenzlong
您需要在您的函数文件夹中运行“firebase functions:config:get > .runtimeconfig.json”,以便将变量存储在 .runtimeconfig.json 中并且可以由模拟器访问。
我知道了。 我忘了写这个信息。
这是functions/.runtimeconfig.json
:
{
"environment": {
"project_id": "development"
}
}
我可以在 v3.16.0 下访问functions.config().environment. project_id
,但我无法访问最新版本(v3.17.3)。
@mono0926你能为此打开一个新问题吗? 还包括您使用的是什么版本的 firebase-functions?
@laurenzlong
你能为此开一个新问题吗? 还包括您使用的是什么版本的 firebase-functions?
好的,我打开了一个问题👍: https ://github.com/firebase/firebase-tools/issues/629
刚刚更新到 3.17.4 仍然得到:
sudo npm install -g firebase-tools
[sudo] password for marcus:
npm WARN deprecated [email protected]: Use uuid module instead
/usr/bin/firebase -> /usr/lib/node_modules/firebase-tools/bin/firebase
+ [email protected]
updated 4 packages in 555.594s
(xenial)marcus<strong i="6">@localhost</strong>:~$ cd app/
(xenial)marcus<strong i="7">@localhost</strong>:~/app$ firebase serve --only functions
=== Serving from '/home/marcus/Downloads/deko-app'...
⚠ functions: Cannot start emulator. Error: Cannot find module '/usr/lib/node_modules/firebase-tools/node_modules/grpc/src/node/extension_binary/grpc_node.node'
(xenial)marcus<strong i="8">@localhost</strong>:~/app$
并尝试了#442,但没有运气。
附言。 在 xenial (Linux) 上运行
@marcus7777您面临的问题与此问题无关。 尝试删除 firebase-tools 并重新安装它。 如果它不起作用,请打开一个新问题。
我也成功删除了模拟器的本地状态:
$HOME/.config/configstore/@google-cloud/functions-emulator/.functions.json
和类似的文件。
谢谢
你好,
正如@rafasoares所指出的,如果我添加这一行,就会出现问题:
admin.initializeApp(functions.config().firebase);
这是我得到的错误:
➜ functions yarn run shell
yarn run v1.5.1
$ yarn run build && firebase experimental:functions:shell
$ tsc
i functions: Preparing to emulate functions.
⚠ functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
⚠ functions: Error from emulator. Error occurred while parsing your function triggers. Please ensure you have the latest firebase-functions SDK by running "npm i --save firebase-functions@latest" inside your functions folder.
Error: Firebase config variables are not available. Please use the latest version of the Firebase CLI to deploy this function.
at init (/Volumes/HDD/carlosbernal/Dropbox/Wanttu/Futbol/backend/functions/node_modules/firebase-functions/lib/config.js:55:15)
at Object.config (/Volumes/HDD/carlosbernal/Dropbox/Wanttu/Futbol/backend/functions/node_modules/firebase-functions/lib/config.js:29:9)
at Object.<anonymous> (/Volumes/HDD/carlosbernal/Dropbox/Wanttu/Futbol/backend/functions/lib/index.js:5:35)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
No functions emulated.
✨ Done in 11.64s.
此外,当我降级到[email protected]
时,我可以访问 shell,但会出现一个新错误:
➜ functions yarn run shell
yarn run v1.5.1
$ yarn run build && firebase experimental:functions:shell
$ tsc
i functions: Preparing to emulate functions.
⚠ functions: Error from emulator. TypeError: Cannot read property 'split' of undefined
✔ functions: addMessage
firebase >
@laurenzlong也许我错过了什么?
@BernalCarlos正如错误消息所示,请确保您使用的是最新的 firebase-functions 版本。 在你的函数目录中运行以下命令:`npm i --save firebase-functions@latest '
之后,你的 functions/package.json 应该有 firebase-functions 0.8.1
@laurenzlong我已经拥有最新版本的 firebase-functions。 这是我的 package.json:
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "yarn run build && firebase serve --only functions",
"shell": "yarn run build && firebase experimental:functions:shell",
"start": "yarn run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^5.9.1",
"firebase-functions": "^0.8.1"
},
"devDependencies": {
"tslint": "^5.9.1",
"typescript": "^2.7.2"
},
"private": true
}
在 yarn.lock 我也有这个:
...
firebase-functions@^0.8.1:
version "0.8.1"
resolved "https://registry.yarnpkg.com/firebase-functions/-/firebase-functions-0.8.1.tgz#a42fe6d243862c406af16e1c16b1d0a81ec24c03"
dependencies:
"@types/express" "^4.0.33"
"@types/jsonwebtoken" "^7.1.32"
"@types/lodash" "^4.14.34"
"@types/sha1" "^1.1.0"
express "^4.0.33"
jsonwebtoken "^7.1.9"
lodash "^4.6.1"
sha1 "^1.1.1"
...
firebase-admin@^5.9.1:
version "5.9.1"
resolved "https://registry.yarnpkg.com/firebase-admin/-/firebase-admin-5.9.1.tgz#1edf6248d014063f0e473f84fe9d63df18e53807"
dependencies:
"@firebase/app" "^0.1.10"
"@firebase/database" "^0.1.11"
"@google-cloud/firestore" "^0.12.0"
"@google-cloud/storage" "^1.6.0"
"@types/google-cloud__storage" "^1.1.7"
"@types/node" "^8.0.53"
faye-websocket "0.9.3"
jsonwebtoken "8.1.0"
node-forge "0.7.1"
但问题仍然存在。
感谢分享你的 package.json,你能告诉我你的项目目录结构是什么吗? 我们还不支持单声道存储库,因此需要有一个 functions/node_modules/firebase-functions 文件夹。
当然@laurenzlong这是我的项目目录结构,因为 node_modules 文件夹它很大:
使用[email protected] (即 firebase CLI)问题再次出现,它与功能没有直接关系,但如果您回滚到 3.17.4 仿真将起作用。
我在 firebase-tools repo 中打开了相应的问题:firebase/firebase-tools#691
@Rulsky与[email protected] ,对于一个非常简单的功能,它失败并出现不同的错误:
// index.ts
import * as fbAdmin from "firebase-admin";
import * as fbFunctions from "firebase-functions";
fbAdmin.initializeApp(fbFunctions.config().firebase);
export const addMessage = fbFunctions.https.onRequest((request, response) => {
const original = request.query.text;
response.send(original);
});
错误:
➜ functions yarn run shell
yarn run v1.5.1
$ yarn run build && firebase experimental:functions:shell
$ tsc
i functions: Preparing to emulate functions.
⚠ functions: Failed to emulate addMessage
No functions emulated.
✨ Done in 12.71s.
我还注意到,在运行 firebase CLI 时会创建一个日志文件,但之后会立即删除此类文件。 有没有办法让这个日志文件不被删除?
@BernalCarlos您是否已将服务管理员密钥放入项目的functions
目录中? 并在你的 shell 中导出了 GOOGLE_APPLICATION_CREDENTIALS 全局变量?
让它发挥作用至关重要https://firebase.google.com/docs/functions/local-emulator
如果您不使用 Firebase 身份验证或其他 Google API,则实际上不需要设置 GOOGLE_APPLICATION_CREDENTIALS。 所以@BernalCarlos我认为您的问题与https://github.com/firebase/firebase-tools/issues/691相同,我已经修复并链接到该问题。
我有一个干净的项目,只有 CLI 创建的功能,当我包含const app = admin.initializeApp(functions.config().firebase);
时它不起作用。 该项目是用
```
“依赖”:{
"firebase-admin": "~5.8.1",
“firebase 功能”:“^0.8.1”
}
````
@Jhony0311你可能也受到#691 的影响
我可以使用firebase deploy --only functions
但不能使用firebase serve --only functions
。
它在执行“npm run serve”后保持加载,
i 函数:准备模拟函数。
警告:您使用的是 Node.js v10.5.0,但 Google Cloud Functions 仅支持 v6.11.5。
⚠ 函数:无法模拟 getSomeData
i 函数:未找到 HTTPS 函数。 如果您想模拟其他类型的函数,请使用 firebase functions:shell 。
firebase version: 3.19.3
这是我的代码:
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.getSomeData = functions.https.onRequest((req, res) => {
admin.firestore().doc('feedback/d8pGxmML5ZKLYEy5jyhm').get()
.then(doc => res.send(doc.data()))
.catch(err => res.status(500).send(err));
});
有什么建议?
嗨,节点 10 的问题
使用旧版本。 例如,第 8 版。
2018 年 7 月 4 日,01:46 +0200,Nicolas Sturm [email protected]写道:
我可以使用 firebase deploy --only 功能,但没有 firebase serve --only 功能。
它在执行“npm run serve”后保持加载,
i 函数:准备模拟函数。
警告:您使用的是 Node.js v10.5.0,但 Google Cloud Functions 仅支持 v6.11.5。
⚠ 函数:无法模拟 getSomeData
i 函数:未找到 HTTPS 函数。 如果您想模拟其他类型的函数,请使用 firebase functions:shell 。
火力基地版本:3.19.3
这是我的代码:
'使用严格';常量函数 = 要求('firebase-functions');
const admin = require('firebase-admin');admin.initializeApp();
export.getSomeData = functions.https.onRequest((req, res) => {
admin.firestore().doc('feedback/d8pGxmML5ZKLYEy5jyhm').get()
.then(doc => res.send(doc.data()))
.catch(err => res.status(500).send(err));
});
有什么建议?
—
你收到这个是因为你被提到了。
直接回复此电子邮件,在 GitHub 上查看它,或将线程静音。
如果它对其他人有帮助,我试图使用fulfillment
的 Dialogflow 并在本地编辑和测试代码。 我有这个错误。 解决它的方法与@rafasoares所说的类似。
为了解决这个问题,我不得不复制使用的 package.json Dialogflow,而不是生成的firebase init
。 似乎是版本控制问题。
我有完全相同的问题。 我认为我们只是打算在我们的各个部署阶段使用环境变量,而只使用 JSON 配置文件。 我很想看到一个修复,运行 npm 绝对不能解决这个问题。
就我而言,我通过先运行firebase deploy
然后运行firebase serve
来修复错误,然后错误就消失了
我已将所有 firebase-tools、firebase-admin、firebase-functions 更新到最新版本
"dependencies": {
"firebase-admin": "^7.3.0",
"firebase-functions": "^2.3.0",
"googleapis": "^32.0.0",
"mailgun-js": "^0.18.0",
"moment": "^2.20.1",
"request": "^2.81.0",
"request-promise": "^4.2.1"
},
"private": true,
"devDependencies": {
"firebase-functions-test": "^0.1.2",
"firebase-tools": "^6.8.0",
"mocha": "^5.2.0",
"rewire": "^4.0.1",
"sinon": "^6.0.0",
"underscore": "^1.9.1"
},
但是,当我想运行 firebase 函数 shell 时,我仍然看到这个错误
i functions: Preparing to emulate functions.
⚠ functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
⚠ functions: Error from emulator. Error occurred while parsing your function triggers.
@Randyanto你好,我不能告诉你明确的答案,但我可能会给你一些线索。 我也遇到了同样的错误。 就我而言,我无法很好地工作require('firebase')
。 所以,我尝试降级' [email protected] '。
我做npm install --save [email protected]
。 最后,我可以解决这个问题。
也许您有与 firebase 或其他功能相关的问题。
检查您拥有的每个版本依赖项。 祝你好运。
最有用的评论
尝试从函数目录中运行
npm run serve
而不是firebase serve --only functions
,这可能会或可能不会起作用,具体取决于您的 package.json 文件的配置方式。