firebase-tools
firebase-tools copied to clipboard
Firebase tools upgrade to 11.10.0 no 'Access-Control-Allow-Origin' CORS issue in emulator
[REQUIRED] Environment info
**firebase-tools: 11.10.0
**Platform: Windows 10
[REQUIRED] Test case
[REQUIRED] Steps to reproduce
When upgrading from firebase-tools 11.9.0 to 11.10.0, I get the following error when calling a back-end function in the emulator:
Access to fetch at 'http://localhost:5001/acro-test-68a41/us-central1/checkUserExistenceAndSetOnCoachOrManager' from origin 'http://localhost:4300/' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Call with firebase-js-sdk (angularFire): import { getFunctions, httpsCallable, HttpsCallable, HttpsCallableOptions } from 'firebase/functions';
return httpsCallable(getFunctions(), functionName, options);
Cloud function:
export const checkSomething = functions.https.onCall(
async (params: CheckSomethingParams, context: CallableContext): Promise
This issue does not seem to follow the issue template. Make sure you provide all the required information.
+1 @bkendall Confirm having the same issue since updating to latest firebase-tools
Interestingly, it is only happening on one of our httpsCallable functions. There is not much difference in that function vs the others that are working
[REQUIRED] Environment info
firebase-tools: 11.14.1
Platform: macOS
[REQUIRED] Test case
// functions/myFunc.ts
export default functions.https.onCall(async () => {return Promise.resolve(true)});
// functions/index.ts
import myFunc from './myFunc';
export {myFunc};
// client/index.ts
import { httpsCallable } from 'firebase/functions';
import { cloudFunctions } from '../firebase';
const callable = httpsCallable(cloudFunctions, 'myFunc');
export async function test() {
const response = await callable();
return response;
}
[REQUIRED] Steps to reproduce
Run the functions emulator Call the test function from the client
[REQUIRED] Expected behavior
The httpsCallable function will get called
[REQUIRED] Actual behavior
Client gets CORS error:
Access to fetch at 'http://localhost:5001/project-id/us-central1/myFunc' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Run the command with --debug flag, and include the logs below.
(please note that I've replaced my project id with project-id for security)
[2022-10-10T19:29:38.481Z] [work-queue] {"queueLength":1,"workRunningCount":1}
[2022-10-10T19:29:38.481Z] [work-queue] {"queueLength":0,"workRunningCount":2}
[2022-10-10T19:29:38.481Z] Accepted request OPTIONS /project-id/us-central1/myFunc --> us-central1-myFunc
[2022-10-10T19:29:38.482Z] [functions] Runtime ready! Sending request! {"metadata":{"emulator":{"name":"functions"},"message":"[functions] Runtime ready! Sending request!"}}
[2022-10-10T19:29:38.483Z] [functions] Got req.url=/project-id/us-central1/myFunc, mapping to path=/ {"metadata":{"emulator":{"name":"functions"},"message":"[functions] Got req.url=/project-id/us-central1/myFunc, mapping to path=/"}}
[2022-10-10T19:29:38.483Z] [worker-pool] Cleaned up workers for us-central1-myFunc: 1 --> 0 {"metadata":{"emulator":{"name":"functions"},"message":"[worker-pool] Cleaned up workers for us-central1-myFunc: 1 --> 0"}}
i functions: Loaded environment variables from .env.
[2022-10-10T19:29:38.541Z] [worker-pool] addWorker(us-central1-myFunc) {"metadata":{"emulator":{"name":"functions"},"message":"[worker-pool] addWorker(us-central1-myFunc)"}}
[2022-10-10T19:29:38.543Z] [worker-pool] Adding worker with key us-central1-myFunc, total=1 {"metadata":{"emulator":{"name":"functions"},"message":"[worker-pool] Adding worker with key us-central1-myFunc, total=1"}}
[2022-10-10T19:29:38.545Z] [work-queue] {"queueLength":1,"workRunningCount":2}
[2022-10-10T19:29:38.545Z] [work-queue] {"queueLength":0,"workRunningCount":3}
[2022-10-10T19:29:38.545Z] Accepted request OPTIONS /project-id/us-central1/myFunc --> us-central1-myFunc
[2022-10-10T19:29:38.546Z] [functions] Runtime ready! Sending request! {"metadata":{"emulator":{"name":"functions"},"message":"[functions] Runtime ready! Sending request!"}}
[2022-10-10T19:29:38.546Z] [functions] Got req.url=/project-id/us-central1/myFunc, mapping to path=/ {"metadata":{"emulator":{"name":"functions"},"message":"[functions] Got req.url=/project-id/us-central1/myFunc, mapping to path=/"}}
[2022-10-10T19:29:38.546Z] [worker-pool] submitRequest(triggerId=us-central1-myFunc) {"metadata":{"emulator":{"name":"functions"},"message":"[worker-pool] submitRequest(triggerId=us-central1-myFunc)"}}
[2022-10-10T19:29:38.546Z] [worker-us-central1-myFunc-584c7629-6b0b-4141-99d1-08615b04c4dc]: BUSY {"metadata":{"emulator":{"name":"functions"},"message":"[worker-us-central1-myFunc-584c7629-6b0b-4141-99d1-08615b04c4dc]: BUSY"}}
[2022-10-10T19:29:38.549Z] [work-queue] {"queueLength":0,"workRunningCount":2}
[2022-10-10T19:29:38.550Z] Oct 10, 2022 3:29:38 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
{"metadata":{"emulator":{"name":"firestore"},"message":"Oct 10, 2022 3:29:38 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n"}}
[2022-10-10T19:29:38.552Z] [worker-us-central1-myFunc-584c7629-6b0b-4141-99d1-08615b04c4dc]: exited {"metadata":{"emulator":{"name":"functions"},"message":"[worker-us-central1-myFunc-584c7629-6b0b-4141-99d1-08615b04c4dc]: exited"}}
[2022-10-10T19:29:38.552Z] [worker-us-central1-myFunc-584c7629-6b0b-4141-99d1-08615b04c4dc]: FINISHED {"metadata":{"emulator":{"name":"functions"},"message":"[worker-us-central1-myFunc-584c7629-6b0b-4141-99d1-08615b04c4dc]: FINISHED"}}
[2022-10-10T19:29:38.633Z] Oct 10, 2022 3:29:38 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
{"metadata":{"emulator":{"name":"firestore"},"message":"Oct 10, 2022 3:29:38 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n"}}
[2022-10-10T19:29:38.665Z] Oct 10, 2022 3:29:38 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
{"metadata":{"emulator":{"name":"firestore"},"message":"Oct 10, 2022 3:29:38 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n"}}
FirebaseError: Failed to load function.
at Timeout._onTimeout (/Users/userName/.config/yarn/global/node_modules/firebase-tools/lib/emulator/functionsRuntimeWorker.js:152:24)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7) {"metadata":{"emulator":{"name":"functions"},"message":{"name":"FirebaseError","children":[],"exit":1,"message":"Failed to load function.","status":500}}}
[2022-10-10T19:29:50.317Z] [work-queue] {"queueLength":0,"workRunningCount":1}
[2022-10-10T19:30:00.428Z] Oct 10, 2022 3:30:00 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
{"metadata":{"emulator":{"name":"firestore"},"message":"Oct 10, 2022 3:30:00 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n"}}
FirebaseError: Failed to load function.
at Timeout._onTimeout (/Users/userName/.config/yarn/global/node_modules/firebase-tools/lib/emulator/functionsRuntimeWorker.js:152:24)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7) {"metadata":{"emulator":{"name":"functions"},"message":{"name":"FirebaseError","children":[],"exit":1,"message":"Failed to load function.","status":500}}}
[2022-10-10T19:30:08.578Z] [work-queue] {"queueLength":0,"workRunningCount":0}
[2022-10-10T19:30:12.393Z] Oct 10, 2022 3:30:12 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
INFO: Detected non-HTTP/2 connection.
{"metadata":{"emulator":{"name":"firestore"},"message":"Oct 10, 2022 3:30:12 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead\nINFO: Detected non-HTTP/2 connection.\n"}}
[2022-10-10T19:30:12.410Z] Oct 10, 2022 3:30:12 PM com.google.cloud.datastore.emulator.firestore.webchannel.FirestoreV1WebChannelAdapter$FirestoreListenHandler onClose
INFO: channel closed
{"metadata":{"emulator":{"name":"firestore"},"message":"Oct 10, 2022 3:30:12 PM com.google.cloud.datastore.emulator.firestore.webchannel.FirestoreV1WebChannelAdapter$FirestoreListenHandler onClose\nINFO: channel closed\n"}}
@bkendall After some more exploration, this seems to occur when more than one emulated functions is firing at/around the same time. If I wait a few seconds and try again so that only one function is firing, it works as expected
This might be confirmed by the debug logs (above) that mention workRunningCount: 2 and BUSY