Firebase错误:“错误分析触发器:找不到模块'./clone.js'”

时间:2018-11-05 22:21:49

标签: firebase google-cloud-storage google-cloud-functions clone firebase-storage

运行DataGridView1.DataSource时收到以下错误消息:

firebase deploy --only functions

这是我的代码,是从documentation复制的:

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

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); }); }); 是这个npm module吗?

1 个答案:

答案 0 :(得分:1)

我将常量移到函数中,错误消失了:

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);
  });

});