gpt4 book ai didi

firebase - 解析错误 : 'import' and 'export' may appear only with 'sourceType: module'

转载 作者:行者123 更新时间:2023-12-05 07:16:58 35 4
gpt4 key购买 nike

我目前正在使用 Google Cloud Functions 和 Firestore。但是我在尝试从父文档获取数据时遇到了问题。我已经在 Internet 上搜索了该问题,但似乎建议的修复方法都不适合我。

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

/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

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

最佳答案

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

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

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

关于firebase - 解析错误 : 'import' and 'export' may appear only with 'sourceType: module' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58994784/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com