0

So I know that this question has been asked quite a lot, and the common answer is adding a region like this:

export.webhookEurope = functions
.region('europe-west1')
.https.onRequest((req, res) => {
    res.send("Hello");
});

But in my case, I'm working with the onCreate method, and sampling the above code in my function just throws me an error. Code looks like this.

export const onCreate = functions.firestore
.document('parent/{id}')
.region('europe-west1')
.onCreate(async (snapshot, context) => {
    // some code which deploys correctly if I leave out the 'region'    
});

So deploying without the 'region' part works fine, but if I leave it in, it gives me the following error:

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! functions@ build: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the functions@ build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Error: functions predeploy error: Command terminated with non-zero exit code2

So what would be the correct way of changing the default region?

1 Answer 1

1

You're putting the call to region() in the wrong part of the builder. It comes before the identification of the product you're triggering on:

export const onCreate = functions
.region('europe-west1')
.firestore
.document('parent/{id}')
.onCreate(async (snapshot, context) => {
    // some code which deploys correctly if I leave out the 'region'    
});

The API reference might be helpful in the future. Especially FunctionBuilder.

Sign up to request clarification or add additional context in comments.

1 Comment

You saved me again Doug, thank you so much. Btw your YT Firebase tutorial is amazing :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.