firebase cloud error Failed to load function definition from source

Viewed 8559

unable to deploy changes to firebase cloud

Action: "Firebase Deploy" in cmd

results:

i  deploying functions
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
+  functions: required API cloudfunctions.googleapis.com is enabled
+  functions: required API cloudbuild.googleapis.com is enabled
i  functions: preparing codebase default for deployment

Error: Failed to load function definition from source: Failed to generate manifest from function source: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in C:\Users\rushikesh.chaskar\IdeaProjects\todosmanager\node_modules\firebase\package.json

5 Answers

I soved it by upgrading the firebase-functions dependency

yarn add firebase-functions

In the functions directory

In my case I had an error in my code that only surfaced when deploying.

The error I got was firebase functions "Failed to generate manifest from function source: TypeError: Cannot read properties of undefined (reading 'toString')"

After about an hour of commenting out everything and then uncommenting a chunk at a time I realized my code wasn't deploying to firebase functions because of a line I wrote that included process.env.FUNCTIONS_EMULATOR.toString(). Apparently when deploying process.env.FUNCTIONS_EMULATOR is null so trying to call toString on it throws an error.

I changed that line to `${process.env.FUNCTIONS_EMULATOR}` and now my firebase functions deploy.

Adding to the never ending list of problems. If you get something like the below error, check your imports.

Failed to load function definition from source: FirebaseError: Failed to load function definition from source: Failed to generate manifest from function source: TypeError: Cannot read properties of undefined (reading 'INTERNAL')

I noticed some outdated Admin SDK instructions had the following:

import {initializeApp} from "firebase-admin";

Where as the correct import is:

import {initializeApp} from "firebase-admin/app";

In my case, the problem was a TypeScript enum which I turned into an array to use in my code. Apparently, firebase-functions doesn't like that.

I ended up defining the array directly in my code without using the enum from my type definitions.

In my case, I forgot to include the subfolder path in the configuration file.

Code(index.ts):

exports.my_group = require('./subfolder/parser')

Error:

Error: Failed to load function definition from source: Failed to generate manifest from function source: Error: Cannot find module './subfolder/parser'

Solution was to change

"include": [
  "src"
]

to

"include": [
  "src", "src/**/*"
 ]

in tsconfig.json file.

Related