【问题标题】:Parsing error: 'import' and 'export' may appear only with 'sourceType: module'解析错误:“import”和“export”可能只出现在“sourceType:module”中
【发布时间】:2019-11-22 12:57:39
【问题描述】:

我目前正在使用 Google Cloud Functions 和 Firestore。但是我在尝试从父文档中获取数据时遇到了问题。我已经在互联网上搜索了这个问题,但似乎没有任何建议的修复对我有用。

以下是我尝试部署时在终端中得到的内容。

/Users/macmini1/Documents/resould-firebase/functions/index.js
  24:1  error  Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

✖ 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!     /Users/macmini1/.npm/_logs/2019-11-22T12_20_27_403Z-debug.log

到目前为止,我已经得出结论,它与我需要的“firebase-admin”有关。 我试图更新所有内容,以及执行相同目标的不同方式。 但似乎没有任何效果。

这是我的代码。

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

var db = admin.firestore();
exports.createBid = functions.firestore.document('auctions/{auctionId}/bids/{bidId}').onCreate(async (snap, context) => {
    const bid = snap.ref;
    const auction = await getAuction(auctionId);

    return bid.set({
        test: auction.end_date
    }, {merge: true}).then(() => {
        console.log("Count is created! " + bidId);
        return null;
    }).catch((error) => {
        console.error("Counter Error writing document: ", error);
        return null;
    });
});

export async getAuction(auctionId) {
    if (!auctionId) return Promise.reject('no userId');
    const auctionSnap = await db.collection('auctions').doc(auctionId).get();
    return auctionSnap.data();
}

这是我的 package.json

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "8"
  },
  "dependencies": {
    "firebase-admin": "^8.8.0",
    "firebase-functions": "^3.3.0"
  },
  "devDependencies": {
    "eslint": "^5.12.0",
    "eslint-plugin-promise": "^4.0.1",
    "firebase-functions-test": "^0.1.6"
  },
  "private": true
}

我的 .eslintrc.json 有 ecmaVersion 2017

希望有人能指出我做错了什么:-)

【问题讨论】:

    标签: firebase google-cloud-firestore google-cloud-functions


    【解决方案1】:

    我也遇到了同样的问题 我已经尝试过了,它对我有用。

    parserOptions: {
    ecmaVersion: 11,
    sourceType: "module",
    },
    

    正确检查 {} 和键值之间的空格 .

    【讨论】:

      猜你喜欢
      • 2018-12-04
      • 2023-04-06
      • 2019-05-08
      • 2017-11-07
      • 1970-01-01
      • 2021-02-02
      • 2020-06-05
      • 2020-04-24
      • 2021-08-08
      相关资源
      最近更新 更多