Reputation: 1
I've set up and express server to run on firebase cloud functions. Now I'm trying to deploy it to firebase with the CLI using "firebase deploy --only functions" but it fails every time, saying there's an unexpected token. I suspect there's a problem with using async arrow functions in the index.js file, but I'm not sure and I also need them for my project.
Here is the index.js file:
const functions = require("firebase-functions");
const express = require("express");
const cors = require("cors");
const { response } = require("express");
const stripe = require("stripe")('superlongtestkey')
//app config
const app = express();
//middleware
app.use(cors({ origin: true}));
app.use(express.json());
//api route
app.post("/payments/create", async (request, response) => {
const total = request.query.total;
const paymentIntent = await stripe.paymentIntents.create({
amount: total,
currency: "usd"
});
response.status(201).send({
clientSecret: paymentIntent.client_secret,
});
});
Here is the error I get when I try to run firebase deploy --only functions:
=== Deploying to 'homunculus-ad003'...
i deploying functions Running command: npm --prefix "$RESOURCE_DIR" run lint
functions@ lint C:..............\Repos\github\amazonhomunculus\functions eslint .
C:..............\Repos\github\amazonhomunculus\functions\index.js
17:56 error Parsing error: Unexpected token =>✖ 1 problem (1 error, 0 warnings)
npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! functions@ lint:
eslint .
npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the functions@ lint script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.npm ERR! A complete log of this run can be found in: npm ERR!
C:..............\AppData\Roaming\npm-cache_logs\2021-07-16T12_20_21_809Z-debug.log events.js:291 throw er; // Unhandled 'error' event ^Error: spawn npm --prefix "%RESOURCE_DIR%" run lint ENOENT at notFoundError (C:..............\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:6:26)
at verifyENOENT (C:\..............\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:40:16) at ChildProcess.cp.emit (C:\..............\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:27:25) at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12) Emitted 'error' event on
ChildProcess instance at: at ChildProcess.cp.emit (C:..............\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\cross-env\node_modules\cross-spawn\lib\enoent.js:30:37) at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12) { code: 'ENOENT', errno: 'ENOENT', syscall: 'spawn npm --prefix "%RESOURCE_DIR%" run lint',
path: 'npm --prefix "%RESOURCE_DIR%" run lint', spawnargs: [] }Error: functions predeploy error: Command terminated with non-zero exit code1
I'm working on a windows machine
Is there a way to bring es7 or later syntax into the server, or another way to deploy to firebase functions???
Upvotes: 0
Views: 601
Reputation: 450
There are two ways to deploy Cloud Functions:
One is through the Google Cloud Console (not the firebase one), although the firebase options are only in preview mode.
The other one is through the firebase deploy command. Which is the intended option for firebase based Functions.
To be able to use ES7 or later syntax you can try Typescript. Cloud Functions runtime is Node.js and Node 14 already supports most of the ES20015-2017 features. So writing on node could be also another option.
And the error seems very similar to this other post and this Github issue so it is most likely due to missing some dependencies in the directory or an issue with the pre-deploy linting script. I would try those solutions.
Upvotes: 0