错误解析错误:将函数部署到firebase时,正则表达式标志无效

时间:2018-05-23 11:39:03

标签: javascript firebase google-cloud-functions

使用firebase为我的android聊天应用项目创建带有node.js的推送通知。当我在通知功能部署我的firebase时,我遇到了一些错误。

这是我在38:11和39:16的index.js ****这是我的index.js ****

'use strict'

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.sendNotification = functions.database.ref('/notification/{user_id}/{notification_id}').onWrite(event => {

const user_id = event.params.user_id;
const notification = event.params.notification;

console.log("The User Id is : ",user_id);

if(!event.data.val()){

return console.log('A Notification has been deleted from database : ', notification_id);
}

const fromUser = admin.database().ref(/notification/${user_id}/{notification_id}).once(value);
return fromUser.then(fromUserResult => {

    const from_user_id = fromUserResult.val().from;
    console.log('You have new notification from : ', from_user_id);

    const userQuery = admin.database().ref(`/Users/${user_id}/${notification_id}`).once('value');
    return userQuery.then(userResult => {

        const userName = userResult.val();
        const deviceToken = admin.database().ref(`/Users/${user_id}/device_token`).once('value');

        return deviceToken.then (result => {

          const token_id = result.val();

          const payload = {
            notification : {

              title : "Friend Request",
              body : `${userName} has sent you request`,
              icon : "default"
            }
          };

          return admin.messaging().sendToDevice(token_id , payload);
        });
  });
});
});
**The cmd give me following result**


C:\Users\Ouneeb Ur Rehman\Desktop\notification function\functions\index.js
  19:40  error  Parsing error: Invalid regular expression flag

✖ 1 problem (1 error, 0 warnings)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: `eslint .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Ouneeb Ur Rehman\AppData\Roaming\npm-cache\_logs\2018-05-23T11_05_23_181Z-debug.log

Error: functions predeploy error: Command terminated with non-zero exit 
I try install and uninstall npn and firebase tools but alls goes to vane 

我获得了firebase令牌ID并存储在数据库中 我是节点js的新手,不能你enter image description here  Plz任何人都可以提供帮助     提前致谢

这是我的通知数据库sinpit

1 个答案:

答案 0 :(得分:0)

你忘记了第19行的引语(并且应该使用简单的引用:Private Sub Worksheet_Change(ByVal Target As Range) Dim MergeWidth As Single Dim cM As Range Dim AutoFitRng As Range Dim CWidth As Double Dim NewRowHt As Double Dim str01 As String str01 = "Note" If Not Intersect(Target, Range(str01)) Is Nothing Then Application.ScreenUpdating = False On Error Resume Next Set AutoFitRng = Range(Range(str01).MergeArea.Address) With AutoFitRng .MergeCells = False CWidth = .Cells(1).ColumnWidth MergeWidth = 0 For Each cM In AutoFitRng cM.WrapText = True MergeWidth = cM.ColumnWidth + MergeWidth Next 'small adjustment to temporary width MergeWidth = MergeWidth + AutoFitRng.Cells.Count * 0.66 .Cells(1).ColumnWidth = MergeWidth .EntireRow.AutoFit NewRowHt = .RowHeight .Cells(1).ColumnWidth = CWidth .MergeCells = True .RowHeight = NewRowHt End With Application.ScreenUpdating = True End If End Sub )。 Firebase数据库需要String而不是正则表达式。 (cf:Reference documentation

第19行应该是:

   public void ShouldEncryptTheValue()
{
   //Getting the instance of session factory using,
   //the NHibernateSessionHelper custom class.  
   //This step could be different in your case.
   //May be the session factory gets injected in some way.
   ISessionFactory sessionFactory = NHibernateSessionHelper.GetSessionFactory();

    //Step - 1 - Opening a NHibernate session using the session factory.
    var session = sessionFactory.OpenSession();

    //Step - 2 - Starting the NHibernate transaction.
    session.BeginTransaction();

    //Step - 3 - Creating an instance of SqlCommand
    IDbCommand command = new SqlCommand();

    //Step - 4 - Setting the connection property of the command instance 
    //with NHibernate session's Connection property.
    command.Connection = session.Connection;

    //Step - 5 - Setting the CommandType property 
    //as CommandType.StoredProcedure
    command.CommandType = CommandType.StoredProcedure;

    //Step - 6 - Setting the CommandText to the name 
    //of the stored procedure to invoke.
    command.CommandText = "encrypt";

    //Step - 7 - Set input parameter, 
    //in our case its "@stringToEncrypt" with the value to encrypt, 
    //in our case "Hello World"
    command.Parameters.Add(new SqlParameter("@stringToEncrypt", "Hello World"));

    //Step - 8 - Set output parameter, in our case "encryptedValue".  
    //Notice that we are specifying the parameter type as second argument 
    //and its size as the third argument to the constructor.  
    //The Direction property is initialized in the initialization block 
    //with ParameterDirection.Output.
    SqlParameter outputParameter = 
        new SqlParameter("@encryptedValue", SqlDbType.VarChar, 255)
                       {
                           Direction = ParameterDirection.Output
                       };
    command.Parameters.Add(outputParameter);

    //Step - 9 - Enlisting the command with the NHibernate transaction.
    session.Transaction.Enlist(command);

    //Step - 10 - Executing the stored procedure.
    command.ExecuteNonQuery();

    //Step - 11 - Getting the value set by the stored procedure 
    //in the output parameter.
    var encryptedValue = 
        ((SqlParameter)command.Parameters["@encryptedValue"]).Value.ToString();
    Console.WriteLine(encryptedValue);

    //Step - 12 - Cleanup.  Committing the NHibernate Transaction 
    //and closing the NHibernate session.
    session.Transaction.Commit();
    session.Close();
}

请注意,Javascript正则表达式可以采用以下形式:

'

这就是为什么elint警告你有关正则表达式标志无效的原因。