0

I am trying to create a task using Google Cloud Tasks but i'm encountering an error.

My code compiles perfectly but when it reaches the Cloud Tasks initialization line:

const data = snap.data();

let expirationInSeconds
if(data.booking_date_ts - Date.now() > 172800000){
    expirationInSeconds = (Date.now() + 172800000) / 1000
}else{
    expirationInSeconds = (Date.now() + 180000) / 1000
}

const project = JSON.parse(process.env.FIREBASE_CONFIG).projectId
const location = 'us-central1'
const queue = 'reminders'

const tasksClient = new CloudTasksClient() // This is the error line
const queuePath = tasksClient.queuePath(project, location, queue)

const url = `https://${location}-${project}.cloudfunctions.net/bookingExpirationCallback`
const docPath = snap.ref.path
const payload = { docPath }

const task = {
    httpRequest: {
        httpMethod: 'POST',
        url,
        body: Buffer.from(JSON.stringify(payload)).toString('base64'),
        headers: {
            'Content-Type': 'application/json',
        },
    },
    scheduleTime: {
        seconds: expirationInSeconds
    }
}

return await tasksClient.createTask({ parent: queuePath, task });

i am getting the following error:

Error: Node.js v10.0.0 is a minimum requirement

which is weird because their documentation says:

Our client libraries follow the Node.js release schedule. Libraries are compatible with all current active and maintenance versions of Node.js.

and my current Node.js version is: v12.16.3

enter image description here

1 Answers1

0

The problem was that my Node.js version was set to 12.16.3 but the process.version was 8.3.2.

How to fix it?

Modify package.json engine from:

"engines": {
    "node": "8"
  },

to

  "engines": {
    "node": "10"
  },
  • Bro i have the same issue, how to solve this, i did as you told like "engines": { "node": "12.16.3" }, still same error – Pran R.V Jul 22 '20 at 15:07
  • @PranR.V you have to set it to "10", not to 12.16.3. Let me know if it worked – Skizzotrick Jul 22 '20 at 16:58
  • It didnt, i am using serverless framework so in serverless.yml there is a field called runtime which when set to node10 it worked – Pran R.V Jul 23 '20 at 04:42