Search code examples
firebasefirebase-toolsfirebase-extensions

Firebase extension Error : emulated services will use a demo configuration and attempts to access non-emulated services for this project will fail


I am building an extension by reading this official documentation and getting error in 4 step, while start emulator in firebase extension firebase emulators:start --project=demo-test.

Error :

C:\Users\RAJENDRA A VERMA\Desktop\Firebase Extension\rtdb-uppercase- 
messages\functions\integration-tests>firebase emulators:start --project=demo-test

i  emulators: Starting emulators: functions, database, extensions
i  emulators: Detected demo project ID "demo-test", emulated services will use a demo configuration and attempts to access non-emulated services for this project will fail.
i  emulators: Shutting down emulators.

Error: An unexpected error has occurred.

error in firebase-debug.log

[debug] [2023-08-16T15:34:36.952Z] ----------------------------------------------------------------------
[debug] [2023-08-16T15:34:36.955Z] Command:       C:\Program Files\nodejs\node.exe C:\Users\RAJENDRA A VERMA\AppData\Roaming\npm\node_modules\firebase-tools\lib\bin\firebase.js emulators:start --project=demo-test
[debug] [2023-08-16T15:34:36.956Z] CLI Version:   12.4.8
[debug] [2023-08-16T15:34:36.956Z] Platform:      win32
[debug] [2023-08-16T15:34:36.957Z] Node Version:  v18.16.0
[debug] [2023-08-16T15:34:36.968Z] Time:          Wed Aug 16 2023 21:04:36 GMT+0530 (India Standard Time)
[debug] [2023-08-16T15:34:36.969Z] ----------------------------------------------------------------------
[debug] 
[debug] [2023-08-16T15:34:37.137Z] Object ".extensions" in "firebase.json" has unknown property: {"additionalProperty":"rtdb-uppercase-messages"}
[debug] [2023-08-16T15:34:37.147Z] > 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"]
[debug] [2023-08-16T15:34:37.147Z] > authorizing via signed-in user ([email protected])
[debug] [2023-08-16T15:34:37.333Z] java version "20.0.1" 2023-04-18

[debug] [2023-08-16T15:34:37.334Z] Java(TM) SE Runtime Environment (build 20.0.1+9-29)
Java HotSpot(TM) 64-Bit Server VM (build 20.0.1+9-29, mixed mode, sharing)

[debug] [2023-08-16T15:34:37.390Z] Parsed Java major version: 20
[info] i  emulators: Starting emulators: functions, database, extensions {"metadata":{"emulator":{"name":"hub"},"message":"Starting emulators: functions, database, extensions"}}
[info] i  emulators: Detected demo project ID "demo-test", emulated services will use a demo configuration and attempts to access non-emulated services for this project will fail. {"metadata":{"emulator":{"name":"hub"},"message":"Detected demo project ID \"demo-test\", emulated services will use a demo configuration and attempts to access non-emulated services for this project will fail."}}
[debug] [2023-08-16T15:34:37.398Z] Successfully read params from rtdb-uppercase-messages.env
[debug] [2023-08-16T15:34:37.399Z] Error: ENOENT: no such file or directory, open 'C:\Users\RAJENDRA A VERMA\Desktop\Firebase Extension\rtdb-uppercase-messages\functions\integration-tests\extensions\rtdb-uppercase-messages.env.0'
[debug] [2023-08-16T15:34:37.399Z] Error: ENOENT: no such file or directory, open 'C:\Users\RAJENDRA A VERMA\Desktop\Firebase Extension\rtdb-uppercase-messages\functions\integration-tests\extensions\rtdb-uppercase-messages.env.demo-test'
[debug] [2023-08-16T15:34:37.400Z] Error: ENOENT: no such file or directory, open 'C:\Users\RAJENDRA A VERMA\Desktop\Firebase Extension\rtdb-uppercase-messages\functions\integration-tests\extensions\rtdb-uppercase-messages.env.local'
[debug] [2023-08-16T15:34:37.419Z] [extensions] Source code valid for ../..
[info] i  emulators: Shutting down emulators. {"metadata":{"emulator":{"name":"hub"},"message":"Shutting down emulators."}}
[debug] [2023-08-16T15:34:37.624Z] TypeError: Cannot read properties of undefined (reading 'filter')
    at getNonSecretEnv (C:\Users\RAJENDRA A VERMA\AppData\Roaming\npm\node_modules\firebase-tools\lib\extensions\emulator\optionsHelper.js:62:33)
    at getExtensionFunctionInfo (C:\Users\RAJENDRA A VERMA\AppData\Roaming\npm\node_modules\firebase-tools\lib\extensions\emulator\optionsHelper.js:49:26)
    at async ExtensionsEmulator.toEmulatableBackend (C:\Users\RAJENDRA A VERMA\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\extensionsEmulator.js:146:82)
    at async Promise.all (index 0)
    at async ExtensionsEmulator.getExtensionBackends (C:\Users\RAJENDRA A VERMA\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\extensionsEmulator.js:137:25)
    at async Object.startAll (C:\Users\RAJENDRA A VERMA\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\controller.js:209:36)
    at async C:\Users\RAJENDRA A VERMA\AppData\Roaming\npm\node_modules\firebase-tools\lib\commands\emulators-start.js:32:43
[error] 
[error] Error: An unexpected error has occurred.

file structure :

rtdb-uppercase-messages
├── functions
│   ├── integration-tests
│   │   ├── extensions
│   │   │   └── rtdb-uppercase-messages.env
│   │   ├── .firebaserc
│   │   ├── firebase.json
│   │   └── integration-test.spec.js
│   ├── node_modules
│   ├── index.js
│   ├── package-lock.json
│   └── package.json
├── README.md
├── PREINSTALL.md
├── POSTINSTALL.md
├── CHANGELOG.md
└── extension.yaml

in extension.yaml :

name: rtdb-uppercase-messages
version: 0.0.1
specVersion: v1beta  # Firebase Extensions specification version; don't change

# Friendly display name for your extension (~3-5 words)
displayName: Convert messages to upper case

# Brief description of the task your extension performs (~1 sentence)
description: >-
  Converts messages in RTDB to upper case

author:
  authorName: Your Name
  url: https://your-site.example.com

license: Apache-2.0  # Required license

# Public URL for the source code of your extension
sourceUrl: https://github.com/your-name/your-repo

resources:
  - name: makeuppercase
    type: firebaseextensions.v1beta.function
    properties:
      eventTrigger:
        eventType: providers/google.firebase.database/eventTypes/ref.create
        # DATABASE_INSTANCE (project's default instance) is an auto-populated
        # parameter value. You can also specify an instance.
        resource: projects/_/instances/${DATABASE_INSTANCE}/refs/messages/{pushId}/original
      runtime: "nodejs18"

in firebase.json :

{
  "emulators": {
    "functions": {
      "port": 5001
    },
    "ui": {
      "enabled": true
    },
    "singleProjectMode": true,
    "database": {
      "port": 9000
    }
  },
  "extensions": {
    "rtdb-uppercase-messages": "../.."
  }
}

Where is the mistake happening? Where am I making a mistake?


Solution

  • firebaser here

    Sorry to hear that you ran into this - This looks like a bug with the Extensions emulator. I've opened https://github.com/firebase/firebase-tools/issues/6271 describing more details about what's happening & should have a fix out in the next release for firebase-tools.

    For now, the workaround is to add a params section to the top level of your extension.yaml. It can even be empty, i.e.:

    name: rtdb-uppercase-messages
    version: 0.0.1
    specVersion: v1beta 
    
    # Rest of your spec...
    
    # Add any params section
    params: []