1

I am following this tutorial about using google cloud tasks to trigger a cloud function. However I am unable to upload the code because i get thrown this error. "Require statement not part of import statement" and it references this code:

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

Ive tried multiple different resolves such as this one and this one. I am following the code and instructions exactly with no success. Does anybody have any suggestions for fixing this or another way of importing google cloud tasks? Any help would be great!

Edit:

I have triedimport {CloudTasksClient} from "@google-cloud/tasks" and it throws back errors at my variables such as

(Type 'string' is not assignable to type '"POST" | HttpMethod | "HTTP_METHOD_UNSPECIFIED" | "GET" | "HEAD" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | null | undefined'.)

here is my packages.json file:

    {
  "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
}

1 Answers1

2

look into this documentation and change accordingly https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-var-requires.md