firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Default Extension code from ext:dev:init has many TypeScript errors

Open adelespinasse opened this issue 1 month ago • 3 comments

The Firebase Extension code created by firebase ext:dev:init does not build correctly when using TypeScript.

[REQUIRED] Environment info

firebase-tools: 14.26.0

Platform: Ubuntu under WSL2 on Windows 11

[REQUIRED] Test case

"Steps to reproduce" below are all that is needed.

[REQUIRED] Steps to reproduce

mkdir extensionname
cd extensionname
firebase ext:dev:init
# Select Typescript when asked
# Select yes or no when asked about eslint
# Select yes when asked whether to install dependencies
npm run build --prefix=functions

[REQUIRED] Expected behavior

The extension should build without errors.

[REQUIRED] Actual behavior

TypeScript prints a large number of errors, beginning with:

node_modules/@types/node/child_process.d.ts:310:9 - error TS1165: A computed property name in an ambient context must refer to an expression whose type is a literal type or a 'unique symbol' type.

310         [Symbol.dispose](): void;
            ~~~~~~~~~~~~~~~~

node_modules/@types/node/child_process.d.ts:310:17 - error TS2339: Property 'dispose' does not exist on type 'SymbolConstructor'.

310         [Symbol.dispose](): void;
                    ~~~~~~~

There are many more errors after that. The error summary at the end reads:

Found 50 errors in 18 files.

Errors  Files
     2  node_modules/@types/node/child_process.d.ts:310
     2  node_modules/@types/node/dgram.d.ts:595
     1  node_modules/@types/node/events.d.ts:403
     9  node_modules/@types/node/fs.d.ts:331
     2  node_modules/@types/node/fs/promises.d.ts:498
     1  node_modules/@types/node/inspector.d.ts:49
     2  node_modules/@types/node/net.d.ts:739
     2  node_modules/@types/node/perf_hooks.d.ts:827
     3  node_modules/@types/node/readline.d.ts:54
     3  node_modules/@types/node/sqlite.d.ts:233
     4  node_modules/@types/node/stream.d.ts:628
     2  node_modules/@types/node/test.d.ts:2205
     6  node_modules/@types/node/timers.d.ts:34
     1  node_modules/@types/node/ts5.6/index.d.ts:29
     4  node_modules/@types/node/v8.d.ts:418
     2  node_modules/@types/node/web-globals/streams.d.ts:10
     2  node_modules/@types/node/worker_threads.d.ts:558
     2  src/index.ts:14

The errors in node_modules/@types/node/ appear to be a result of firebase ext:dev:init installing Typescript 4.9. Packages firebase-functions and firebase-admin both depend indirectly on version 22.x and/or version 24.x of @types/node, which is for a more recent version of TypeScript. The obvious solution is to update the generated extension code to use a recent version of TypeScript. (This really should have been done long ago anyway; same goes for the default functions code generated by firebase init. Typescript 5.0 came out in March 2023.)

The two errors in src/index.ts are caused by importing from firebase-functions without specifying v1, as required by recent versions of the package when using 1st generation Functions. The line:

import * as functions from "firebase-functions";

should be:

import * as functions from "firebase-functions/v1";

adelespinasse avatar Nov 25 '25 02:11 adelespinasse

Thanks for providing detailed steps to reproduce the issue as well as for sharing your observations @adelespinasse! it does look like we would need to update the our extension templates to use a newer version of TypeScript and update the code template as well.

I'll discuss this issue with our engineering and mark this as reproducible.

aalej avatar Nov 25 '25 17:11 aalej

👋 @joehan @aalej,

I'd like to open a PR to fix this issue.

Planned changes:

  • Bump TypeScript from ^4.9.0 to ^5.3.0 in both package.lint.json and package.nolint.json
  • Add "skipLibCheck": true to tsconfig.json to handle @types/node compatibility
  • Update the import in index.ts from "firebase-functions" to "firebase-functions/v1" to align with firebase-functions v6

This will eliminate the 50+ TypeScript errors users currently encounter when running npm run build --prefix=functions after scaffolding a new extension.

Is it okay to proceed, or is someone already working on this?

Thanks!

singhaditya73 avatar Dec 11 '25 16:12 singhaditya73

Go for it (and that plan sounds good)! I was looking at getting AI to do this for us, but it seems to be struggling to validate the changes.

joehan avatar Dec 11 '25 18:12 joehan