You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i functions: Watching "/Users/hitsthings/Code/in8/in8app-server/functions" for Cloud Functions...
> before
> Trace: hmm
> at Object.<anonymous> (/Users/hitsthings/Code/in8/in8app-server/functions/lib/index.js:6:9)
> at Module._compile (internal/modules/cjs/loader.js:1085:14)
> at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
> at Module.load (internal/modules/cjs/loader.js:950:32)
> at Function.Module._load (internal/modules/cjs/loader.js:790:12)
> at Module.require (internal/modules/cjs/loader.js:974:19)
> at require (internal/modules/cjs/helpers.js:93:18)
> at initializeRuntime (/Users/hitsthings/Code/in8/in8app-server/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:640:29)
> at processTicksAndRejections (internal/process/task_queues.js:95:5)
> at async handleMessage (/Users/hitsthings/Code/in8/in8app-server/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:684:20)
> after
> (SOME ERROR FROM ./user)???
[REQUIRED] Actual behavior
Code is loaded twice and prints:
i functions: Watching "/Users/hitsthings/Code/in8/in8app-server/functions" for Cloud Functions...
> before
> Trace: hmm
> at Object.<anonymous> (/Users/hitsthings/Code/in8/in8app-server/functions/lib/index.js:6:9)
> at Module._compile (internal/modules/cjs/loader.js:1085:14)
> at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
> at Module.load (internal/modules/cjs/loader.js:950:32)
> at Function.Module._load (internal/modules/cjs/loader.js:790:12)
> at Module.require (internal/modules/cjs/loader.js:974:19)
> at require (internal/modules/cjs/helpers.js:93:18)
> at initializeRuntime (/Users/hitsthings/Code/in8/in8app-server/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:640:29)
> at processTicksAndRejections (internal/process/task_queues.js:95:5)
> at async handleMessage (/Users/hitsthings/Code/in8/in8app-server/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:684:20)
> after
> before
> [ '[DEFAULT]in8app' ]
> Trace: hmm
> at Object.<anonymous> (/Users/hitsthings/Code/in8/in8app-server/functions/lib/index.js:6:9)
> at Module._compile (internal/modules/cjs/loader.js:1085:14)
> at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
> at Module.load (internal/modules/cjs/loader.js:950:32)
> at Function.Module._load (internal/modules/cjs/loader.js:790:12)
> at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:199:29)
> at ModuleJob.run (internal/modules/esm/module_job.js:183:25)
> at async Loader.import (internal/modules/esm/loader.js:178:24)
> at async initializeRuntime (/Users/hitsthings/Code/in8/in8app-server/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:649:29)
> at async handleMessage (/Users/hitsthings/Code/in8/in8app-server/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:684:20)
⚠ functions: The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument. In most cases you only need to call initializeApp() once. But if you do want to initialize multiple apps, pass a second argument to initializeApp() to give each app a unique name.
⚠ Your function was killed because it raised an unhandled error.
Looking at the relevant lines of functionsEmulatorRuntime.js in that trace brings up:
My code is being require()'d, then dynamicImport()'d. Both times, initializeApp() is run successfully (which is bad).
If I conditionally call initializeApp() only if there are no apps yet, I do get a (somewhat) useful message about node-fetch. But it was too late in my case:
⚠ functions: Must use import to load ES Module: /Users/hitsthings/Code/in8/in8app-server/functions/node_modules/node-fetch/src/index.js
require() of ES modules is not supported.
require() of /Users/hitsthings/Code/in8/in8app-server/functions/node_modules/node-fetch/src/index.js from /Users/hitsthings/Code/in8/in8app-server/functions/lib/user/in8-subscription.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/hitsthings/Code/in8/in8app-server/functions/node_modules/node-fetch/package.json.
Suggested fixes
Add logging of the initial ESM error before retrying and potentially creating new errors.
Switch the automatic ESM compile to a configuration option OR properly clean up the environment before running the code a second time.
The text was updated successfully, but these errors were encountered:
This issue does not have all the information required by the template. Looks like you forgot to fill out some sections. Please update the issue with more information.
[REQUIRED] Environment info
firebase-tools: 9.23.3
Platform: macOS
[REQUIRED] Test case
[REQUIRED] Steps to reproduce
firebase emulators:start
with index.js that looks like (generated from TS, similar to above):Note that I require my code after calling initializeApp. Before I added the console noise it was just (TS):
[REQUIRED] Expected behavior
Code is loaded once and prints:
[REQUIRED] Actual behavior
Code is loaded twice and prints:
Looking at the relevant lines of
functionsEmulatorRuntime.js
in that trace brings up:My code is being
require()
'd, thendynamicImport()
'd. Both times,initializeApp()
is run successfully (which is bad).If I conditionally call
initializeApp()
only if there are no apps yet, I do get a (somewhat) useful message aboutnode-fetch
. But it was too late in my case:Suggested fixes
The text was updated successfully, but these errors were encountered: