简体   繁体   English

解析错误:“import”和“export”可能只出现在“sourceType:module”中

[英]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.

相关问题 AWS CDK NodejsFunction:导入导出为“export =”的模块 - AWS CDK NodejsFunction: import a module exported as "export =" Firebase 用户导入/导出 - Firebase user import / export Python 3.10.7 导入错误 ModuleNotFoundError:没有名为“_bz2”的模块 - Python 3.10.7 Import Error ModuleNotFoundError: No module named '_bz2' 尝试导入错误:“firebase/app”不包含默认导出(导入为“firebase”) - Attempted import error: 'firebase/app' does not contain a default export (imported as 'firebase') 解析触发器时出错:找不到模块“csv-parse/sync” - Error parsing triggers: Cannot find module 'csv-parse/sync' Python Flask import 未导入的模块错误 - Python Flask import Error of module that isn´t being imported 如何解决此 firebase 导入错误? 找不到模块:错误:Package 路径。 不从 package 导出 - How do I resolve this firebase import error? Module not found: Error: Package path . is not exported from package typescript 从另一个 ts 文件导入 function - 文件不是模块错误 - typescript import function from another ts file - file is not a module error 由于 ClientError:磁盘验证失败 [OVF 文件解析错误],无法将 VM 导入为 AMI - failed to import VM as AMI due to ClientError: Disk validation failed [OVF file parsing error] GeneratedPluginConstraint,致命错误:找不到模块“firebase_auth”@import firebase_auth; - GeneratedPluginConstraint , Fatal error: module 'firebase_auth' not found @import firebase_auth;
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM