2
votes

I just trying the firebase cloud function. the index.ts is just a hello world. but I got the error when deploying the firebase cloud function.

I just follow along video tutorial from here: https://www.youtube.com/watch?v=DYfP-UIKxH0

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@ lint /Users/muchammadagunglaksana/Documents/Latihan/cloud_function/doug_youtube/functions
> tslint --project tsconfig.json

Running command: npm --prefix "$RESOURCE_DIR" run build

> functions@ build /Users/muchammadagunglaksana/Documents/Latihan/cloud_function/doug_youtube/functions
> tsc

src/index.ts:1:1 - error TS6133: 'functions' is declared but its value is never read.

1 import * as functions from 'firebase-functions';
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 1 error.

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! functions@ build: `tsc`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the functions@ build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/muchammadagunglaksana/.npm/_logs/2019-09-09T03_21_14_265Z-debug.log

Error: functions predeploy error: Command terminated with non-zero exit code2
Muchammads-MacBook-Air:doug_youtube muchammadagunglaksana$ 

here is the index.ts

import * as functions from 'firebase-functions';

// Start writing Firebase Functions
// https://firebase.google.com/docs/functions/typescript

export const helloWorld = functions.https.onRequest((request, response) => {
 response.send("Hello from Firebase!");
});

and this is my package.json

{
  "name": "functions",
  "scripts": {
    "lint": "tslint --project tsconfig.json",
    "build": "tsc",
    "serve": "npm run build && firebase serve --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "8"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase-admin": "^8.0.0",
    "firebase-functions": "^3.1.0"
  },
  "devDependencies": {
    "tslint": "^5.12.0",
    "typescript": "^3.2.2"
  },
  "private": true
}

what should I do ?

2

2 Answers

3
votes

I suspect that you didn't save the source file before deploying. On disk, the function is probably still commented out, which would cause functions to go unused.

0
votes

The issue is with new version of typscript, just disable this property from tsconfig.json "noUnusedLocals": false

{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": false,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src"

] }