Require语句不是import语句的一部分- google可以使用函数和typescript &



我遵循这个教程使用谷歌云任务来触发云功能。然而,我无法上传代码,因为我得到这个错误。Require语句不是import语句的一部分;它引用了下面的代码:

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

我尝试了多种不同的解决方案,比如这个和这个。我完全按照代码和指示执行,但没有成功。有没有人有任何建议修复这个或其他方式导入谷歌云任务?任何帮助都太好了!

编辑:

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

(类型'string'不能赋值给类型'"POST"HttpMethod | "HTTP_METHOD_UNSPECIFIED"|"GET"|"HEAD"|"PUT"|"DELETE"|"PATCH"|"OPTIONS"| null | undefined

这是我的包裹。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
}

查看此文档并进行相应更改https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-var-requires.md

最新更新