roconmachine
roconmachine

Reputation: 2116

Error : Shadowed name: 'request' in Firebase cloud function

Here is a Firebase Cloud Function REST Api code.

import { request } from "https";

const functions = require("firebase-functions");
const admin = require('firebase-admin');
admin.initializeApp();
const firestore = admin.firestore();

export const helloWorld = functions.https.onRequest((request, response) => {

   response.send("Hello from rocon!");
});

Error is :

ERROR: /Users/hello/Computer/Development/server/ts_test/functions/src/index.ts[13, 54]: Shadowed name: 'request'
ERROR: /Users/hello/Computer/Development/server/ts_test/functions/src/index.ts[19, 50]: Shadowed name: 'request'

Upvotes: 3

Views: 1320

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317710

You are defining something called request with this import:

import { request } from "https";

Then you are defining another identifier called request in your function:

export const helloWorld = functions.https.onRequest((request, response) => {

As it stands now, you won't be able to use the request import inside your function because the function can only see the request parameter.

You should change the name of one of them so that the request in the function doesn't shadow (hide) the request from your import.

Upvotes: 4

Related Questions