需求,导出和控制台字段

时间:2018-06-19 09:58:59

标签: javascript android node.js atom-editor

我已经制作了一个脚本,用于向我的Firebase服务器发送推送通知,但是javascript eslint首先为const抛出错误。

然后我在Google上发现我必须在我的.eslintsrc文件中输入ecmaVersion = 6。 我这样做了然后它在require,exports和console字段显示错误。

我使用Atom作为代码的编译器。这是我的代码:

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

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

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

exports.printUrl = functions.database.ref('images/{uid}').onWrite(event => {
    var request = event.data.val();
    var payload = {
        data:{
            url : request.url,
            location : request.location
        }
    };

    admin.messaging().sendToTopic(request.topic, payload)
        .then(function(response){
            console.log("Successfully sent message : ", response);
        })
        .catch(function(error){
            console.log("Error sending message : ", error);
        })
});

1 个答案:

答案 0 :(得分:3)

您需要让eslint知道您在Node环境中工作以摆脱require和exports错误。所以将它添加到你的eslintConfig:

"env": {
   "node": true
 }

为了允许console.log,您必须通过将此规则添加到eslintconfig来打开规则:

"rules": {
  "no-console": 0
 }

您可以在此处找到更多信息:https://eslint.org/docs/user-guide/configuring