randombeans
randombeans

Reputation: 3

I cannot deploy firebase cloud functions: Failed to load function definition from source, No "exports" main defined in D:\

I'm trying to implement Firebase Storage into my Cloud Functions app script. I've been running into a problem where my code won't deploy at this point in the script:

const app = express();
app.engine('hbs',engines.handlebars);
app.set('views','./views');
app.set('view engine','hbs');

admin.initializeApp(functions.config().firebase);

I run into this error:

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 D:\Documents\ShowtapeLibraryAdmin\node_modules\firebase\package.json

I am using Firebase 9.14, Functions 4.1.0, and Google-Cloud/Storage 6.70 as well as Firebase/app 0.8.4.

I've tried updating firebase, checking the code from the tutorial I used for cloud functions as well as updating any other packages and NPM

Here is the full index.js: https://pastebin.com/Q8J0LzCh

I do apologise if I have not properly formatted this question correctly, this is my first Stack Exchange post!

Upvotes: 0

Views: 183

Answers (1)

Dharmaraj
Dharmaraj

Reputation: 50850

Firebase uses a modular, functional syntax starting from version V9.0.0. Try refactoring the code as shown below:

const { initializeApp } = require('firebase/app');

It seems you are trying to use Firebase SDK in a Cloud Function so you should ideally use the Firebase Admin SDK itself and not the client SDK as well. Try updating to latest version of Firebase Admin SDK and refactoring the code as shown below:

const { initializeApp } = require('firebase-admin/app');
const { getStorage } = require('firebase-admin/storage');

const storage = getStorage();

Checkout the documentation for Firebase Admin for Cloud Storage for more information.

Upvotes: 1

Related Questions