-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
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";