[英]Parsing error: 'import' and 'export' may appear only with 'sourceType: module'
Im currently working with Google Cloud Functions and Firestore.我目前正在使用 Google Cloud Functions 和 Firestore。 But i run into problems when trying to get data from a parent document.但是我在尝试从父文档中获取数据时遇到了问题。 I have searched the issue on the internet, but it seems that no of the fixes suggested works for me.我已经在互联网上搜索了这个问题,但似乎没有任何建议的修复程序对我有用。
The following is what i get in the terminal when i try to deploy.以下是我尝试部署时在终端中得到的内容。
/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
So far i have concluded that it has something to do with "firebase-admin" i have required.到目前为止,我已经得出结论,它与我需要的“firebase-admin”有关。 I have tried to update everything, and different ways to execute the same objective.我试图更新所有内容,以及执行相同目标的不同方法。 But nothing seems to works.但似乎没有任何效果。
Here is my code.这是我的代码。
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();
}
And here is my package.json这是我的 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
}
And my.eslintrc.json has ecmaVersion 2017而 my.eslintrc.json 有 ecmaVersion 2017
Hope there is somebody out there who can point out what i am doing wrong:-)希望有人可以指出我做错了什么:-)
You don't need the export
keyword before getAuction()
since it is only used within the module.您不需要在getAuction()
之前使用export
关键字,因为它仅在模块中使用。
Change this:改变这个:
export async getAuction(auctionId) {
to this:对此:
async function getAuction(auctionId) {
I have face the same issue I have tried this and it worked for me.我遇到了同样的问题,我试过这个,它对我有用。
parserOptions: {
ecmaVersion: 11,
sourceType: "module",
},
Check spaces properly Between {} and key value.正确检查 {} 和键值之间的空格。
Try adding this to your .eslintrc.js
or .eslintrc.cjs
file:尝试将此添加到您的.eslintrc.js
或.eslintrc.cjs
文件中:
parserOptions: {
ecmaVersion: "latest",
ecmaVersion: 11,
sourceType: "module"
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.