firebase / firebase/firebase-functions

vague error message on newer versions of CLI: "Failed to load function definition from source:..."

Open
#1,230 2 comments 1 reaction 0 assignees View on GitHub
api: functions feature request
Dominant language
TypeScript
Stars
1.1k
Forks
232
Avg merge
20h 46m
Merged PRs (30d)
15

Description

### [REQUIRED] Environment info

**firebase-tools:** v10.9.0 to v11.8.0

**Platform:** macOS

### [REQUIRED] Test case

On a project that requires `functions.config()`, remove the `.runtimeconfig.json` file from the project and run the functions emulator. Based on the official docs at https://firebase.google.com/docs/functions/local-emulator#web-version-9

### [REQUIRED] Steps to reproduce

1. Create a simple script `test.js` with the following contents:
```
const functions = require("firebase-functions");
const { region } = functions.config().functions;
console.log("my functions region: ", region);
...
// define some cloud functions

// then import test.js in your index.js file
```
'region' is a sample [Functions environment variable](https://firebase.google.com/docs/functions/config-env#set_environment_configuration_with_the) whose `firebase functions:config:get` output looks like this:
```
{
"functions": {
"region": "us-central1"
}

```

2. Run the Functions emulator with debug logging: `firebase emulators:start --debug`

### [REQUIRED] Expected behavior

The cloud functions should run as usual if we had a valid `.runtimeconfig.json` file.
However, if we legitimately don't have the file locally, **the emulator should rightly fail with a helpful error message** such as below (which **versions 10.8.0 and below** produce):

```
...
[warn] ⚠ It looks like you're trying to access functions.config().functions but there is no value there. You can learn more about setting up config here: https://firebase.google.com/docs/functions/local-emulator {"metadata":{"emulator":{"name":"functions"},"message":"It looks like you're trying to access functions.config().functions but there is no value there. You can learn more about setting up config here: https://firebase.google.com/docs/functions/local-emulator"}}
[warn] ⚠ TypeError: Cannot destructure property 'region' of 'functions.config(...).functions' as it is undefined.
at Object. (~/functions/test.js:2:9)
at Module._compile (node:internal/modules/cjs/loader:1095:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:816:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:93:18)
at Object. (~/functions/index.js:3:16)
at Module._compile (node:internal/modules/cjs/loader:1095:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10) {"metadata":{"emulator":{"name":"functions"},"message":"TypeError: Cannot destructure property 'region' of 'functions.config(...).functions' as it is undefined.\n at Object. (~/functions/test.js:2:9)\n at Module._compile (node:internal/modules/cjs/loader:1095:14)\n at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)\n at Module.load (node:internal/modules/cjs/loader:975:32)\n at Function.Module._load (node:internal/modules/cjs/loader:816:12)\n at Module.require (node:internal/modules/cjs/loader:999:19)\n at require (node:internal/modules/cjs/helpers:93:18)\n at Object. (~/functions/index.js:3:16)\n at Module._compile (node:internal/modules/cjs/loader:1095:14)\n at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)"}}
[warn] ⚠ We were unable to load your functions code. (see above) {"metadata":{"emulator":{"name":"functions"}}}
...
```

### [REQUIRED] Actual behavior

An error occurs, but the message `firebase-debug.log` is not as helpful/detailed as in previous versions of the CLI:

```
...
[error] Error: Failed to load function definition from source: Failed to generate manifest from function source: TypeError: Cannot destructure property 'region' of 'functions.config(...).functions' as it is undefined.
...
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.