Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript eslint error for require, export and console field

I have made a script for sending push notifications to my Firebase server, but javascript eslint is throwing error for const first.

Then I found on Google that I have to put ecmaVersion = 6 in my .eslintsrc file. I did that then it is showing error on require, exports and console field.

I am using Atom as my compiler for code. This is my code:

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);
        })
});
like image 887
Aashay Chaturvedi Avatar asked Mar 05 '23 23:03

Aashay Chaturvedi


1 Answers

You need to let eslint know that you're working in a Node environment to get rid of the require and exports errors. So by adding this to your eslintConfig:

"env": {
   "node": true
 }

In order to allow the console.log, you will have to turn on the rule by adding this to your eslintconfig:

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

You can find more information here: https://eslint.org/docs/user-guide/configuring

like image 195
SO267 Avatar answered Mar 11 '23 10:03

SO267