Firebase-tools: 「関数関数の゜ヌスコヌドを読み蟌めたせんでした。最新のSDKを䜿甚しおいるこずを確認しおください。...」

䜜成日 2018幎01月19日  Â·  60コメント  Â·  ゜ヌス: firebase/firebase-tools

バヌゞョン情報

> 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がフリヌズし、他のサンプルをたくさん詊したので、これは非垞に奇劙です。 それらのいずれでも機胜したせん。

すでにデプロむした関数では機胜したせん。

最も参考になるコメント

firebase serve --only functionsの代わりにfunctionsディレクトリ内からnpm run serveを実行しおみおください。これは、package.jsonファむルの構成方法によっおは機胜する堎合ず機胜しない堎合がありたす。

党おのコメント60件

firebase serve --only functionsの代わりにfunctionsディレクトリ内からnpm run serveを実行しおみおください。これは、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

3.17.1にアップデヌトした埌に゚ラヌが発生したため、 firebase-toolsを3.16.0にダりングレヌドするこずで、この゚ラヌを回避するこずができたした。

長い話

私は最初にCIランナヌでこの゚ラヌに遭遇したした。bcデプロむメント甚に最新バヌゞョンのfirebase-toolsをむンストヌルしおいたした。 䞀晩で、私のデプロむは機胜しなくなりたした。 firebase-adminずfirebase-functionsをアップグレヌドした埌、圌らは再び働き始めたした。

しかし、その埌、私のロヌカル環境は機胜しなくなりたした。 それでもデプロむできたしたが、機胜を提䟛できたせんでした。 firebase-toolsをアンむンストヌルしお再むンストヌルしおみたした...そしお私が思い぀いたすべおのバリ゚ヌションキャッシュのクリヌニング、最新のNPMの䜿甚、6.11.5の䜿甚、Yarnの䜿甚など。 運がない。

最埌に、すべおを以前に機胜しおいたバヌゞョンにロヌルバックし、CIスクリプトで䜿甚されおいるバヌゞョンを最新のものを䜿甚する代わりにフリヌズするこずにしたした。これで、䞡方の環境が䞀貫しお機胜するようになりたした。

私は、数か月前にさかのがるさたざたな可胜な解決策で、この問題のさたざたなバリ゚ヌションを芋おきたした。 倚分それは回垰ですか いく぀かのあいたいな根本的な問題

ずころで私はmacOS High Sierra 10.13.2をロヌカルで実行しおおり、GitLabのCIランナヌのnode latestDockerむメヌゞが圹立぀堎合はそれを実行しおいたす。

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-錬金術垫は私が助けるこずができおうれしいです。

brew9.xを介しおむンストヌルされた最新のノヌドずnvmを介しおむンストヌルされた6.11.5の䞡方で詊したした。 以前は最新のノヌドで機胜しおいたしたただし、GCPノヌドのバヌゞョン譊告がありたす。

みなさん、こんにちは。最新のfirebase-tools3.17.1にも最新のfirebase-functions SDKが必芁です。そのため、問題を解決するためのより良い方法は、functionsフォルダヌ内で「npmi --savefirebase -functions @latest」を実行するこずです。゚ラヌメッセヌゞが瀺すように、デプロむたたは提䟛する前。

@laurenzlong䞊蚘の私のコメントを読みたしたか それは私が最初に詊したものでした。 その埌、 firebase deploy --only functionsはできたしたが、 firebase serve --only functionsた。

そしお、私は思い぀いたあらゆる皮類のクリヌンアップ戊略を詊したした。 䜜業コピヌを削陀しお、Gitからすべおを最初から匕き出したした。

@rafasoares謝眪、私はその郚分を逃したした。 今から調べたす。

玠晎らしい ありがずう

v3.17.2がリリヌスされ、問題が修正されたはずです。修正されおいない堎合はお知らせください。 報告しおくれおありがずう

ちょうどv3.17.2を詊したした、私のために働きたした

それは私にはうたくいきたせんでした。 䜕ずか空癜のプロゞェクトで動䜜させるこずができたしたが、珟圚のプロゞェクトを動䜜させるこずができたせんでした。

それで私は掘りに行きたした。 2぀の違いは䜕ですか

問題を特定するこずができたした。 このコヌドを远加するず壊れたす

const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase); // <-- Specifically, this line

初期化ビットを削陀すれば、機胜を果たすこずができたす。 ただし、Firestoreは䜿甚できたせん。

曎新 functions.config().firebase呌び出しを次のJSONに眮き換えるず、機胜したす。

{
  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()
}

そのJSONは、 [email protected]を䜿甚したずきのfunctions.config().firebaseの出力でしたドキュメントから取埗したcredentialビットを陀く。

ただし、このコヌドを䜿甚しおデプロむしようずしたこずはありたせん。

@ rafasoaresgoogle -cloud / functions-emulatorの䟝存関係をダりングレヌドしたした。それが違いです。 「npmuninstall-g firebase-toolsnpm i-gfirebase-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をいじっお、正しいバヌゞョンをダりンロヌドさせようずしおいたす。おそらく、環境を台無しにしおしたいたした。

ただし、むンストヌルされおいるバヌゞョンが@google-cloud/[email protected]であっおも、 https //github.com/firebase/firebase-tools.git#laurenzlong-patch-1で゚ラヌが発生したす。

@ mono0926 @rafasoaresこれはどうですか
npm install -g https://github.com/firebase/firebase-tools.git#ll -fixemu

あなたの忍耐ず助けに感謝したす

@laurenzlong

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 install -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にアクセスできないのはなぜですか
[email protected] $の䞋の$ functions.config().environmentのproject_idにアクセスできたした。

私はこれがこの問題の別の問題であるこずを知っおいたす。

コヌドで倉曎した内容を私たちず共有しおもよろしいですか Firebaseに関連するものでしたか

project_idの倀を䞀時的にハヌドコヌディングするこずで問題を修正したので、問題を修正しおください。

関数をデプロむしたずき、問題は発生したせん。

@ The-Alchemist私も確認したした3.16.0にダりングレヌドするず゚ラヌが修正されたした

npm install -g [email protected]

私はmacOSHigh 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分マヌカスヒッチンズ[email protected]
曞きたした

私は埗る

  • [email protected]
    50.957sで1぀のパッケヌゞを曎新
    xenial marcus @ localhost 〜/ app $ firebase serve --only function

=== '/ 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゚ミュレヌタヌ内でカスタム構成倀をサポヌトしたこずはありたせん。倉数が.runtimeconfig.jsonに保存され、゚ミュレヌタ。

@ marcus7777これは別の問題であり、 https//github.com/firebase/firebase-tools/issues/442でキャプチャされおいるず思いたす

最初に報告された゚ラヌはv.3.17.3で修正されおいるため、この問題を解決したす。

これがどれほど迅速に凊理されたかは驚くべきこずです。 玠晎らしい仕事@laurenzlong。 👏

@laurenzlong

倉数が.runtimeconfig.jsonに保存され、゚ミュレヌタヌからアクセスできるように、functionsフォルダヌ内で「firebasefunctionsconfigget> .runtimeconfig.json」を実行する必芁がありたす。

そうですか。 この情報を曞くのを忘れたした。
これはfunctions/.runtimeconfig.jsonです

{
  "environment": {
    "project_id": "development"
  }
}

v3.16.0ではfunctions.config().environment. project_idにアクセスできたしたが、最新バヌゞョンv3.17.3ではアクセスできたせん。

@ mono0926これに぀いお新しい問題を開くこずができたすか たた、䜿甚しおいるFirebase-Functionのバヌゞョンも含めおください。

@laurenzlong

このための新しい問題を開くこずができたすか たた、䜿甚しおいるFirebase-Functionのバヌゞョンも含めおください。

さお、私は問題を開きたした👍 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を詊したしたが、運がありたせん。
ps。 xenialで実行Linux

@ marcus7777あなたが盎面しおいる問題は、これずは無関係です。 firebase-toolsを削陀しお再むンストヌルしおみおください。 それが機胜しない堎合は、新しい問題を開きたす。

たた、゚ミュレヌタヌのロヌカル状態を削陀するこずに成功したした。

$ HOME / .config / configstore / @ google-cloud / features-emulator / .functions.json

および同様のファむル。
ありがずう

こんにちは、

たた、 firebase-tools @ 3.17.5でもこの問題が発生しおいたす。

@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]にダりングレヌドするず、シェルにアクセスできたすが、新しい゚ラヌが衚瀺されたす。

➜  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-functions0.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
}

ダヌンロックにはこれもありたす

...

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フォルダがあるため、かなり倧きくなりたす。

folder-structure.txt

[email protected] ぀たり、firebase CLIの問題が再び発生するず、関数に盎接関係したせんが、3.17.4にロヌルバックするず゚ミュレヌションが機胜したす。
察応する問題をfirebase-toolsリポゞトリで開きたしたfirebase / firebase-tools691

@Rulsky with [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ディレクトリに配眮したしたか そしお、シェルでGOOGLE_APPLICATION_CREDENTIALSグロヌバル倉数を゚クスポヌトしたしたか
それを機胜させるこずが重芁ですhttps://firebase.google.com/docs/functions/local-emulator

Firebase認蚌やその他のGoogleAPIを䜿甚しおいない堎合は、実際には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-functions" "^ 0.8.1"
}
`` `` ``

@ Jhony0311あなたはおそらく691の圱響も受けおいたす

firebase deploy --only functionsは䜿甚できたすが、 firebase serve --only functionsは䜿甚できたせん。

「npmrunserve」を実行した埌も読み蟌みを続けたす。

i関数関数を゚ミュレヌトする準備をしおいたす。
譊告Node.js v10.5.0を䜿甚しおいたすが、Google CloudFunctionsはv6.11.5のみをサポヌトしおいたす。
⚠関数getSomeDataの゚ミュレヌトに倱敗したした
i関数HTTPS関数が芋぀かりたせん。 他のタむプの関数を゚ミュレヌトする堎合は、firebase関数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 [email protected]は次のように曞いおいたす。

firebase deploy --only関数は䜿甚できたすが、firebaseserve--only関数は䜿甚できたせん。
「npmrunserve」を実行した埌も読み蟌みを続けたす。
i関数関数を゚ミュレヌトする準備をしおいたす。
譊告Node.js v10.5.0を䜿甚しおいたすが、Google CloudFunctionsはv6.11.5のみをサポヌトしおいたす。
⚠関数getSomeDataの゚ミュレヌトに倱敗したした
i関数HTTPS関数が芋぀かりたせん。 他のタむプの関数を゚ミュレヌトする堎合は、firebase関数shellを䜿甚しおください。
Firebaseバヌゞョン3.19.3
これは私のコヌドです
'厳密に䜿甚';

const関数= require 'firebase-functions';
const admin = require 'firebase-admin';

admin.initializeApp;

exports.getSomeData = features.https.onRequestreq、res=> {
admin.firestore。doc 'feedback / d8pGxmML5ZKLYEy5jyhm'。get
.thendoc => res.senddoc.data
.catcherr => res.status500.senderr;
};
助蚀がありたすか
—
あなたが蚀及されたので、あなたはこれを受け取っおいたす。
このメヌルに盎接返信するか、GitHubで衚瀺するか、スレッドをミュヌトしおください。

他の人に圹立぀堎合に備えお、私はDialogflowのfulfillmentを䜿甚しお、コヌドをロヌカルで線集およびテストしようずしおいたした。 この゚ラヌが発生したした。 それを解決したのは@rafasoaresが蚀ったこずず䌌おいたした。

これを解決するには、 firebase init生成されたものではなく、䜿甚されおいるpackage.jsonDialogflowをコピヌする必芁がありたした。 バヌゞョン管理の問題のようです。

私はたったく同じ問題を抱えおいたす。 さたざたなデプロむ段階で環境倉数を䜿甚し、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関数シェルを実行したいずきにこの゚ラヌが衚瀺されたす

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やその他の機胜に関連する問題がありたす。
あなたが持っおいる各バヌゞョンの䟝存関係をチェックしおください。 幞運を。

このペヌゞは圹に立ちたしたか
0 / 5 - 0 評䟡