TypeError: Cannot convert object to primitive value
See original GitHub issue[REQUIRED] Environment info
firebase-tools: 8.3.0 and later
Platform: Windows
[REQUIRED] Test case
firebase emulators:start
[REQUIRED] Steps to reproduce
npm i firebase-tools@8.3.0 -g firebase emulators:start
[REQUIRED] Expected behavior
D:\workspace\firebasetest>npm i firebase-tools@8.2.0 -g
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
D:\Users\yang\AppData\Roaming\npm\firebase -> D:\Users\yang\AppData\Roaming\npm\node_modules\firebase-tools\lib\bin\firebase.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules\firebase-tools\node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ firebase-tools@8.2.0
added 1 package from 1 contributor, removed 1 package and updated 1 package in 11.003s
D:\workspace\firebasetest>firebase emulators:start
i emulators: Starting emulators: functions, firestore, pubsub
+ hub: emulator hub started at http://localhost:4400
! Your requested "node" version "10" doesn't match your global version "12"
+ functions: functions emulator started at http://localhost:5001
i firestore: firestore emulator logging to firestore-debug.log
+ firestore: firestore emulator started at http://localhost:8080
i firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
i pubsub: pubsub emulator logging to pubsub-debug.log
+ pubsub: pubsub emulator started at http://localhost:8085
i functions: Watching "D:\workspace\firebasetest\functions" for Cloud Functions...
> [functions] Start functions
+ functions[updateRestaurantRate]: firestore function initialized.
+ functions[pubsubFn]: pubsub function initialized.
+ functions[cronRestaurantRanking]: pubsub function initialized.
+ functions[scheduledFunctionCrontab]: pubsub function initialized.
+ emulators: All emulators started, it is now safe to connect.
[REQUIRED] Actual behavior
D:\workspace\firebasetest>npm i firebase-tools@8.3.0 -g
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
D:\Users\yang\AppData\Roaming\npm\firebase -> D:\Users\yang\AppData\Roaming\npm\node_modules\firebase-tools\lib\bin\firebase.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules\firebase-tools\node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ firebase-tools@8.3.0
added 1 package from 1 contributor, removed 1 package and updated 1 package in 9.576s
D:\workspace\firebasetest>firebase emulators:start
i emulators: Starting emulators: functions, firestore, pubsub
! Your requested "node" version "10" doesn't match your global version "12"
i firestore: Firestore Emulator logging to firestore-debug.log
! hosting: The hosting emulator is configured but there is no hosting configuration. Have you run firebase init hosting?
i pubsub: Pub/Sub Emulator logging to pubsub-debug.log
i functions: Watching "D:\workspace\firebasetest\functions" for Cloud Functions...
! TypeError: Cannot convert object to primitive value
at Proxy.<anonymous> (D:\Users\yang\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:311:83)
at Object.<anonymous> (D:\workspace\firebasetest\functions\lib\index.js:13:7)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at D:\Users\yang\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:660:33
at Generator.next (<anonymous>)
! We were unable to load your functions code. (see above)
- You may be able to run "npm run build" in your functions directory to resolve this.
I tired “npm run build” in my functions, it does not work.
D:\workspace\firebasetest>cd functions
D:\workspace\firebasetest\functions>npm run build
> functions@ build D:\workspace\firebasetest\functions
> tsc
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Cannot convert object to primitive value - Stack Overflow
most of the Javascript objects have toString() method inherited from Object.prototype . but some of them that have a null prototype , not...
Read more >Uncaught TypeError: Cannot convert object to primitive value ...
I'm seeing the following error upgrading from 2.9 to 2.11.0: Uncaught TypeError: Cannot convert object to primitive value toString is being ...
Read more >Object to primitive conversion - The Modern JavaScript Tutorial
In case of such operations, objects are auto-converted to primitives, and then the operation is carried out over these primitives and results in ......
Read more >Cannot convert object to primitive value | The Node.js Master ...
Your browser can't play this video. ... Bonus Lecture - TypeError : Cannot convert object to primitive value | The Node.js Master Class....
Read more >Object to Primitive Conversion in JavaScript - W3docs
String conversion happens when we output an object like alert(obj) and in contexts like that. ToPrimitive. It is possible to enhance string and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Also present in 8.4.0. It was a regression in 8.3.0, and it’s not fixed yet 😦 The solution is to downgrade to 8.2.0
For what it’s worth, I get the same error with both Node 10 and with Node 12, on both Windows and Mac.
Digging into what @rosariopfernandes described, I tracked my issue down to this line in my code:
admin.initializeApp(functions.config().firebase);
In my case, there was nothing in my firebase function config (I’m thinking I copied that line from an earlier firebase admin tutorial), so I changed the line to:
admin.initializeApp();
and it started working. Obviously not a great solution, especially if you do have actual configuration values you need to pass into
initializeApp()
but it lets me use 8.4.0 now, with the slick new emulator UI.Hope that’s useful for someone.