Open Exac opened 2 months ago
Currently, if you switch to NodeJS 18 and run the emulator, you will run into an error caused by esbuild.
$ nvm use 18
$ nx build functions
$ node node_modules/firebase-tools/lib/bin/firebase.js emulators:start
i emulators: Starting emulators: auth, functions, firestore, database, hosting, pubsub, storage, eventarc
i firestore: Firestore Emulator logging to firestore-debug.log
✔ firestore: Firestore Emulator UI websocket is running on 9150.
i database: Database Emulator logging to database-debug.log
i pubsub: Pub/Sub Emulator logging to pubsub-debug.log
i hosting[nx-firebase-proj]: Serving hosting files from: packages/nx-firebase-proj-app/public
✔ hosting[nx-firebase-proj]: Local server: http://127.0.0.1:5000
i ui: Emulator UI logging to ui-debug.log
i functions: Watching "/home/exac/example-org/dist/packages/functions" for Cloud Functions...
⚠ functions: package.json indicates an outdated version of firebase-functions. Please upgrade using npm install --save firebase-functions@latest in your functions directory.
⚠ functions: Please note that there will be breaking changes when you upgrade.
⚠ functions: Your requested "node" version "16" doesn't match your global version "18". Using node@18 from host.
i functions: Loaded environment variables from .env, .env.local.
Serving at port 8424
Error: Dynamic require of "util" is not supported
at file:///home/exac/example-org/dist/packages/functions/main.js:12:9
at node_modules/firebase-functions/lib/logger/index.js (file:///home/exac/example-org/dist/packages/functions/main.js:465:18)
at __require2 (file:///home/exac/example-org/dist/packages/functions/main.js:15:51)
at node_modules/firebase-functions/lib/params/types.js (file:///home/exac/example-org/dist/packages/functions/main.js:549:19)
at __require2 (file:///home/exac/example-org/dist/packages/functions/main.js:15:51)
at node_modules/firebase-functions/lib/params/index.js (file:///home/exac/example-org/dist/packages/functions/main.js:872:19)
at __require2 (file:///home/exac/example-org/dist/packages/functions/main.js:15:51)
at node_modules/firebase-functions/lib/common/encoding.js (file:///home/exac/example-org/dist/packages/functions/main.js:960:20)
at __require2 (file:///home/exac/example-org/dist/packages/functions/main.js:15:51)
at node_modules/firebase-functions/lib/v2/providers/https.js (file:///home/exac/example-org/dist/packages/functions/main.js:43834:22)
⬢ functions: Failed to load function definition from source: FirebaseError: Functions codebase could not be analyzed successfully. It may have a syntax or runtime error
┌─────────────────────────────────────────────────────────────┐
│ ✔ All emulators ready! It is now safe to connect your app. │
│ i View Emulator UI at http://127.0.0.1:4000/ │
└─────────────────────────────────────────────────────────────┘
One possible fix is to modify the packages/functions/project.json
:
{
"targets": {
"build": {
"executor": "@nx/esbuild:esbuild",
"options": {
"esbuildOptions": {
"banner":{
"js":"const require = (await import('node:module')).createRequire(import.meta.url);const __filename = (await import('node:url')).fileURLToPath(import.meta.url);const __dirname = (await import('node:path')).dirname(__filename);"
}
}
}
}
}
}
That said, this is with just the basic helloWorld
example function uncommented, and initializeApp
imported and called. I'm not sure if there are more issues with a more complex app.
According to the documentation, NodeJS 16 is going to be decommissioned is January:
https://cloud.google.com/functions/docs/runtime-support