Ошибка функции развертывания firebase CLIEngine не является конструктором - PullRequest
0 голосов
/ 04 мая 2020

Я запускаю функцию развертывания firebase для своего проекта и весь исходный код, который я беру из репозитория на github ,

, но когда я это делаю, ошибка всегда возникает, и следующая ошибка для функций развертывания

=== Deploying to 'bacaberita-id'...

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@ lint /home/halim/Documents/firebase/bacaberita/functions
> eslint .

TypeError: CLIEngine is not a constructor
    at Object.execute (/home/halim/Documents/firebase/bacaberita/functions/node_modules/eslint/lib/cli.js:211:28)
    at Object.<anonymous> (/home/halim/Documents/firebase/bacaberita/functions/node_modules/eslint/bin/eslint.js:107:28)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! functions@ lint: `eslint .`
npm ERR! Exit status 2
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!     /home/halim/.npm/_logs/2020-05-04T13_55_20_707Z-debug.log

Error: functions predeploy error: Command terminated with non-zero exit code2

этот код из .eslintr c. json

{
  "env": {
      "es6": true,
      "node": true
  },
  "parser": "babel-eslint",
  "parserOptions": {
      "ecmaVersion": 2017,
      "sourceType": "module"
  },
  "extends": "eslint:recommended",
  "rules": {
      "camelcase": [2, {"properties": "never"}],
      "no-console": 0
  }
}

код из пакета. json

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "axios": "0.19.2",
    "firebase-admin": "8.11.0",
    "firebase-functions": "3.6.1",
    "package.json": "^2.0.1"
  },
  "devDependencies": {
    "babel-eslint": "10.1.0",
    "eslint": "6.8.0",
    "eslint-plugin-promise": "4.2.1",
    "firebase-tools": "8.2.0"
  },
  "private": true,
  "engines": {
    "node": "8"
  }
}

и код из индекса. js

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

// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
// exports.helloWorld = functions.https.onRequest((request, response) => {
//  response.send("Hello from Firebase!");
// });
const axios = require('axios');

// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');

// The Firebase Admin SDK to access the Firebase Realtime Database.
const admin = require('firebase-admin');
const app = admin.initializeApp();
const db = admin.firestore()
db.settings({ timestampsInSnapshots: true })

const config = functions.config().config
const apiKey = process.env.API_KEY || config.api_key || app.options_.apiKey
const firebaseDynamicLinkApi = `https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=${apiKey}`;
const domainUriPrefix = config.domain_uri_prefix || 'https://bacaberitaku.page.link'; // TODO: move this `domainUriPrefix` to config
const URL_COLLECTION = config.url_collection || 'urls';

exports.addUrl = functions.https.onRequest(async (req, res) => {
    const link = req.query.url || req.body.url || null;
    console.log(JSON.stringify(req.headers, null, 4))

    try {
        console.log(`Getting shorten URL for: ${link}`);
        let result = await axios.post(firebaseDynamicLinkApi, {
            dynamicLinkInfo: {
                domainUriPrefix,
                link,
            },
            suffix: {
                option: 'SHORT'
            }
        })

        // Store the result to Firestore
        try {
            const data = Object.assign(result.data, {
                clientInformation: req.headers,
                originalUrl: link,
                created: new Date()
            })
            const shortenKey = data.shortLink.split('/').slice(-1).pop()
            const docRef = await db.collection(URL_COLLECTION).doc(shortenKey).set(data);
            console.log("Document written with ID: ", docRef.id);
        } catch (error) {
            console.error("Error adding document: ", error);
        }

        res.json(result.data);
    } catch (e) {
        console.error(e.message);
        res.status(500).json('error');
    }
});


exports.analytics = functions.https.onRequest(async (req, res) => {
    const shortDynamicLink = req.query.shortLink || req.body.shortLink || null;
    const durationDays = req.query.durationDays || req.body.durationDays || 30;

    const requestUrl = `https://firebasedynamiclinks.googleapis.com/v1/${shortDynamicLink}/linkStats?durationDays=${durationDays}&key=${apiKey}`;

    try {
        console.log(`Getting statistics for: ${shortDynamicLink}`);
        let result = await axios.get(requestUrl)
        res.json(result.data);
    } catch (e) {
        console.error(e.message);
        res.status(500).json('error');
    }
})

и если у вас есть полное руководство по использованию или работе с хранилище firebase-shortten-url от duyetdev пожалуйста, дайте мне знать.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...