Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

While trying to follow the Add Firebase to your JavaScript project on an empty git repository that will be used for a TypeScript project, I got the following error when I ran firebase deploy:

> functions@ build /Users/mosofsky/Documents/Developer/abcplan/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/mosofsky/.npm/_logs/2019-09-06T03_00_54_557Z-debug.log

Error: functions predeploy error: Command terminated with non-zero exit code2

Since I'm following Google's getting-started guide, I expected everything to work.

like image 335
Michael Osofsky Avatar asked Dec 05 '22 09:12

Michael Osofsky


1 Answers

The root cause is that a) a variable is declared but not used, and b) the TypeScript compiler is configured to flag unused variables as an error.

That configuration is overkill in a basic setup, in my opinion. Perhaps future edits to functions setup will fix this.

As others have pointed out, the ideal choice is simply to use the variable, i.e. make it "not unused".

Sometimes parameter to functions are needed or at least useful to declare but not use. In that case you can prefix with _, and then tell TypeScript that unused variables with a leading underscore can be ignored.

As a last resort, you could tell TypeScript to ignore all unused variables. Change this line in tsconfig.json so an unused variable is no longer an "error" - not recommended:

$ cat functions/tsconfig.json
{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,  // <-- change to false. Not recommended!
    ...
like image 171
Andrew E Avatar answered Dec 07 '22 23:12

Andrew E