【问题标题】:Require statement not part of import statement - google could functions and typescript要求声明不是导入声明的一部分 - 谷歌云功能和打字稿
【发布时间】:2021-10-18 05:01:40
【问题描述】:

我正在关注this tutorial 关于使用谷歌云任务触发云功能。但是我无法上传代码,因为我得到了这个错误。 “要求语句不是导入语句的一部分”,它引用了以下代码:

const {CloudTasksClient} = require("@google-cloud/tasks");

我尝试了多种不同的解析方式,例如this one 和this one。我完全按照代码和说明进行操作,但没有成功。是否有人对修复此或其他导入谷歌云任务的方式有任何建议?任何帮助都会很棒!

编辑:

我已经尝试过import {CloudTasksClient} from "@google-cloud/tasks",它会在我的变量中抛出错误,例如

(类型 'string' 不可分配给类型 '"POST" | HttpMethod | "HTTP_METHOD_UNSPECIFIED" | "GET" | "HEAD" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | null |未定义'。)

这是我的 packages.json 文件:

    {
  "name": "functions",
  "scripts": {
    "lint": "eslint --ext .js,.ts .",
    "build": "tsc",
    "serve": "npm run build && firebase emulators:start --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "12"
  },
  "main": "lib/index.js",
  "dependencies": {
    "@google-cloud/tasks": "^2.3.6",
    "firebase-admin": "^9.6.0",
    "firebase-functions": "^3.15.3"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^3.9.1",
    "@typescript-eslint/parser": "^3.8.0",
    "eslint": "^7.6.0",
    "eslint-config-google": "^0.14.0",
    "eslint-plugin-import": "^2.22.0",
    "firebase-functions-test": "^0.2.0",
    "typescript": "^3.8.0"
  },
  "private": true
}

【问题讨论】:

  • 你试过import {CloudTasksClient} from "@google-cloud/tasks"吗?您在 Cloud 函数中使用哪种语言? Javascript 还是 Typescript?
  • 你的 packages.json 文件是什么?可以分享一下吗?
  • @Dharmaraj 我试过了,它在代码中产生了一堆错误,我把它们附加到我的问题上。我正在使用打字稿
  • @guillaumeblaquiere 我已经为你附上了我的 packages.json 文件!

标签: firebase types google-cloud-functions google-cloud-tasks


【解决方案1】:
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多