FYI: I have tried the solutions here, but did not work.
I am trying to organize my firebase cloud functions into individual files. I just have one function export file for now as a test.
I have a folder called functions
in my root directory with a file called helloWorld.ts
and an index.ts
file:
/functions/helloWorld.ts
:
import * as functions from 'firebase-functions'
export const helloWorld = functions.https.onRequest((request, response) => {
functions.logger.info('Hello logs!', { structuredData: true })
response.send('Hello from Firebase!')
})
/functions/index.ts
:
// import all functions as needed
import { helloWorld } from './helloWorld'
export { helloWorld }
This is a Nuxt 3 app, so when I run the build command (npm run build
), it compiles the overall app code (including the functions
folder) into a folder for distribution. This seems to work fine.
However, after the build stage, I run firebase emulators:start
and get the following error:
PS C:\Users\XXX\Desktop\work\XXX> firebase emulators:start
i emulators: Starting emulators: functions, hosting
! functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, firestore, database, pubsub, storage
+ functions: Using node@16 from host.
+ functions: Using node@16 from host.
i hosting[XXX]: Serving hosting files from: .output/public
+ hosting[XXX]: Local server: http://localhost:5000
i ui: Emulator UI logging to ui-debug.log
i functions: Watching "C:\Users\XXX\Desktop\work\XXX\.output\server" for Cloud Functions...
+ functions[us-central1-server]: http function initialized (http://localhost:5001/XXX/us-central1/server).
i functions: Watching "C:\Users\XXX\Desktop\work\XXX\functions" for Cloud Functions...
i emulators: Shutting down emulators.
i ui: Stopping Emulator UI
! Emulator UI has exited upon receiving signal: SIGINT
i hosting: Stopping Hosting Emulator
i hub: Stopping emulator hub
i logging: Stopping Logging Emulator
Error: Failed to load function definition from source: Failed to generate manifest from function source: SyntaxError: Cannot use import statement outside a module
PS C:\Users\XXX\Desktop\work\XXX> npm run build
Thus, I edited the functions/package.json
file to include:
"type": "module"
But, I still get the above error! Any ideas how to fix?