I have a project that successfully deploys to firebase functions using the Node 8 engine from my local dev environment to firebase. I have been trying to get it working with CloudBuild, however, I get an syntax error due to using the async keyword:
/workspace/functions/lib/index.js:13
Step #5: app.get('XXXXXXXXX', async (req, resp) => {
Step #5: ^
Step #5:
Step #5: SyntaxError: Unexpected token (
Step #5: at createScript (vm.js:56:10)
Step #5: at Object.runInThisContext (vm.js:97:10)
Step #5: at Module._compile (module.js:549:28)
Step #5: at Object.Module._extensions..js (module.js:586:10)
Step #5: at Module.load (module.js:494:32)
Step #5: at tryModuleLoad (module.js:453:12)
Step #5: at Function.Module._load (module.js:445:3)
Step #5: at Module.require (module.js:504:17)
Step #5: at require (internal/module.js:20:19)
Step #5: at /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:21:11
Indicating that the node engine is not async/await aware, ie not Node 8. The engine is set in package.json and works from my local environment.
"engines": {
"node": "8"
}
The deployment is using a firebase container as described in the documentation:
- name: 'gcr.io/[PROJECT_NAME]/firebase'
args: [ 'deploy', '-P', 'prod', '-f', '--only', 'functions','--token', '${_FIREBASE_TOKEN}']
Could CloudBuild be deploying to a different/internal endpoint for firebase functions that doesn't support Node8 and therefore downgrading silently?
Or is there something else that I have missed?
I've tried to prove this theory by changing .tsconfig to target es2015 instead of es2017 and removed the engines section from package.json. The result is the function deployed to a Node8 function?
Step #5: deploying functions
Step #5: functions: ensuring necessary APIs are enabled...
Step #5: functions: all necessary APIs are enabled
Step #5: functions: preparing functions directory for uploading...
Step #5: functions: packaged functions (91.42 KB) for uploading
Step #5: functions: functions folder uploaded successfully
Step #5: functions: updating Node.js 8 function XXXXXX(us-central1)...
Step #5: functions[XXXXXXX(us-central1)]: Successful update operation.
Step #5:
Step #5: Deploy complete!
I think this is because a node 8 function already existed so it was just an update rather than create, but maybe indicates that the code parser is node6 based and ignoring the engine setting when deployed via cloudbuild?