Require 语句不是 import 语句的一部分 - google 可以函数和打字稿
Require statement not part of import statement - google could functions and typescript
我正在关注 this tutorial 关于使用 google 云任务触发云函数的内容。但是我无法上传代码,因为我被抛出了这个错误。 “Require statement not part of import statement”它引用了这段代码:
const {CloudTasksClient} = require("@google-cloud/tasks");
我尝试了多种不同的解决方案,例如 and 。我完全按照代码和说明进行操作,但没有成功。有人对解决此问题或其他导入 google 云任务的方法有任何建议吗?任何帮助都会很棒!
编辑:
我已经尝试过import {CloudTasksClient} from "@google-cloud/tasks"
,它会在我的变量中返回错误,例如
(Type 'string' is not assignable to type '"POST" | HttpMethod | "HTTP_METHOD_UNSPECIFIED" | "GET" | "HEAD" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | null | undefined'.)
这是我的 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
}
我正在关注 this tutorial 关于使用 google 云任务触发云函数的内容。但是我无法上传代码,因为我被抛出了这个错误。 “Require statement not part of import statement”它引用了这段代码:
const {CloudTasksClient} = require("@google-cloud/tasks");
我尝试了多种不同的解决方案,例如
编辑:
我已经尝试过import {CloudTasksClient} from "@google-cloud/tasks"
,它会在我的变量中返回错误,例如
(Type 'string' is not assignable to type '"POST" | HttpMethod | "HTTP_METHOD_UNSPECIFIED" | "GET" | "HEAD" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | null | undefined'.)
这是我的 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
}