Search code examples
firebasegoogle-cloud-storagegoogle-cloud-functionsclonefirebase-storage

Firebase error: "Error parsing triggers: Cannot find module './clone.js'"


When I run firebase deploy --only functions I get this error message:

Error parsing triggers: Cannot find module './clone.js'

Here's my code, copied from the documentation:

const functions = require('firebase-functions');
const admin = require('firebase-admin');

const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucketName = 'myapp.appspot.com';
const filename = './hola_mundo.wav';

admin.initializeApp();

exports.Storage = functions.firestore.document('Test_Value').onUpdate((change, context) => {

  storage.bucket(bucketName).upload(filename, {
    gzip: true,
    metadata: {
      cacheControl: 'no-cache'
    }
  })
  .then(() => {
    console.log(`${filename} uploaded to ${bucketname}`);
  })
  .catch(err => {
    console.error(err);
  });

});

Is clone.js this npm module?


Solution

  • I moved the constants into the function and the error went away:

    const functions = require('firebase-functions');
    const admin = require('firebase-admin');
    
    admin.initializeApp();
    
    exports.Storage = functions.firestore.document('Test_Value').onUpdate((change, context) => {
    
      const {Storage} = require('@google-cloud/storage');
      const storage = new Storage();
      const bucketName = 'myapp.appspot.com';
      const filename = './hola_mundo.wav';
    
      storage.bucket(bucketName).upload(filename, {
        gzip: true,
        metadata: {
          cacheControl: 'no-cache'
        }
      })
      .then(() => {
        console.log(`${filename} uploaded to ${bucketname}`);
      })
      .catch(err => {
        console.error(err);
      });
    
    });