pulyaevskiy / firebase-functions-interop

Firebase Functions Interop Library for Dart.
BSD 3-Clause "New" or "Revised" License
191 stars 52 forks source link

firebase deploy is failing #24

Closed zirinisp closed 6 years ago

zirinisp commented 6 years ago

I am new to Dart and although I love it, I struggle to find my way around it.

I followed the steps on this repo. I get a successful build:

pub run build_runner build [INFO] Generating build script completed, took 250ms [INFO] Reading cached asset graph completed, took 186ms [INFO] Checking for updates since last build completed, took 599ms [INFO] build_node_compilers|entrypoint on node/index.dart:Running dart2js with --checked --packages=.package-7d9a89460320ecd0b7469657b140821c -onode/index.dart.js node/index.dart [INFO] build_node_compilers|entrypoint on node/index.dart:Dart2Js finished with:

Compiled 8,921,032 characters Dart to 378,822 characters JavaScript in 3.03 seconds Dart file (node/index.dart) compiled to JavaScript: node/index.dart.js

[INFO] Running build completed, took 3.4s [INFO] Caching finalized dependency graph completed, took 90ms [INFO] Succeeded after 3.5s with 5 outputs

Then when I try to deploy I get the following:

firebase deploy --only functions --debug [2018-05-11T11:31:43.558Z] ---------------------------------------------------------------------- [2018-05-11T11:31:43.561Z] Command: /usr/local/Cellar/node/9.5.0/bin/node /usr/local/bin/firebase deploy --only functions --debug [2018-05-11T11:31:43.561Z] CLI Version: 3.18.4 [2018-05-11T11:31:43.561Z] Platform: darwin [2018-05-11T11:31:43.561Z] Node Version: v9.5.0 [2018-05-11T11:31:43.562Z] Time: Fri May 11 2018 14:31:43 GMT+0300 (EEST) [2018-05-11T11:31:43.562Z] ----------------------------------------------------------------------

[2018-05-11T11:31:43.576Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"] [2018-05-11T11:31:43.577Z] > authorizing via signed-in user [2018-05-11T11:31:43.579Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/projects/kitespotter2-57429

Fri May 11 2018 14:31:43 GMT+0300 (EEST) [2018-05-11T11:31:44.565Z] <<< HTTP RESPONSE 200 server=nginx, date=Fri, 11 May 2018 11:31:44 GMT, content-type=application/json; charset=utf-8, content-length=122, connection=close, x-content-type-options=nosniff, strict-transport-security=max-age=31536000; includeSubdomains, cache-control=no-cache, no-store [2018-05-11T11:31:44.565Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/database/kitespotter2-57429/tokens

Fri May 11 2018 14:31:44 GMT+0300 (EEST) [2018-05-11T11:31:45.474Z] <<< HTTP RESPONSE 200 server=nginx, date=Fri, 11 May 2018 11:31:45 GMT, content-type=application/json; charset=utf-8, content-length=268, connection=close, x-content-type-options=nosniff, strict-transport-security=max-age=31536000; includeSubdomains, cache-control=no-cache, no-store

=== Deploying to 'kitespotter2-57429'...

i deploying functions Running command: npm --prefix "$RESOURCE_DIR" run lint

functions@ lint /Users/zirinisp/Documents/Dart/SurfSpotterDartCloudFunctions/functions eslint .

/Users/zirinisp/Documents/Dart/SurfSpotterDartCloudFunctions/functions/build/node/index.dart.js 1:106 error Expected '!==' and instead saw '!=' eqeqeq 1:375 error Use '===' to compare with null no-eq-null 1:379 error Expected '===' and instead saw '==' eqeqeq 1:530 error Use '===' to compare with null no-eq-null 1:534 error Expected '!==' and instead saw '!=' eqeqeq 1:551 error Use '===' to compare with null no-eq-null 1:555 error Expected '!==' and instead saw '!=' eqeqeq 1:648 warning Value of 'e' may be overwritten in IE 8 and earlier no-catch-shadow 31:28 error Expected '!==' and instead saw '!=' eqeqeq 31:73 error Expected '===' and instead saw '==' eqeqeq 33:26 error Expected '===' and instead saw '==' eqeqeq 33:58 error Expected '===' and instead saw '==' eqeqeq

then hundreds of similar lines. That end with:

17358:623 error Unexpected comma in middle of array no-sparse-arrays 17358:765 error Unexpected comma in middle of array no-sparse-arrays 17358:850 error Unexpected comma in middle of array no-sparse-arrays 17358:873 error Unexpected comma in middle of array no-sparse-arrays 17358:953 error Unexpected comma in middle of array no-sparse-arrays 17358:1100 error Unexpected comma in middle of array no-sparse-arrays 17358:1128 error Unexpected comma in middle of array no-sparse-arrays 17358:1210 error Unexpected comma in middle of array no-sparse-arrays 17358:1245 error Unexpected comma in middle of array no-sparse-arrays 17358:1279 error Unexpected comma in middle of array no-sparse-arrays 17415:20 error Expected '===' and instead saw '==' eqeqeq 17445:18 error 'i' is already defined no-redeclare 17451:18 error 'i' is already defined no-redeclare 17492:39 error Expected '!==' and instead saw '!=' eqeqeq 17504:6 warning Unexpected function expression prefer-arrow-callback 17507:22 warning Unexpected function expression prefer-arrow-callback

/Users/zirinisp/Documents/Dart/SurfSpotterDartCloudFunctions/functions/build/packages/build_runner/src/server/graph_viz.js 9:27 error Expected '===' and instead saw '==' eqeqeq 9:49 error Expected '===' and instead saw '==' eqeqeq 17:18 error 'i' is already defined no-redeclare 22:25 error Expected '===' and instead saw '==' eqeqeq 68:43 warning Unexpected function expression prefer-arrow-callback 76:37 warning Expected to return a value at the end of function consistent-return 76:37 warning Unexpected function expression prefer-arrow-callback

/Users/zirinisp/Documents/Dart/SurfSpotterDartCloudFunctions/functions/build/packages/node_preamble/preamble.js 9:26 error Expected '!==' and instead saw '!=' eqeqeq 32:13 error Use '===' to compare with null no-eq-null 32:19 error Expected '!==' and instead saw '!=' eqeqeq 33:16 error Use '===' to compare with null no-eq-null 33:22 error Expected '!==' and instead saw '!=' eqeqeq 41:11 error Use '===' to compare with null no-eq-null 41:31 error Expected '===' and instead saw '==' eqeqeq

/Users/zirinisp/Documents/Dart/SurfSpotterDartCloudFunctions/functions/build/packages/node_preamble/preamble.min.js 1:106 error Expected '!==' and instead saw '!=' eqeqeq 1:375 error Use '===' to compare with null no-eq-null 1:379 error Expected '===' and instead saw '==' eqeqeq 1:530 error Use '===' to compare with null no-eq-null 1:534 error Expected '!==' and instead saw '!=' eqeqeq 1:551 error Use '===' to compare with null no-eq-null 1:555 error Expected '!==' and instead saw '!=' eqeqeq 1:648 warning Value of 'e' may be overwritten in IE 8 and earlier no-catch-shadow

✖ 59879 problems (53427 errors, 6452 warnings) 6381 errors, 3211 warnings potentially fixable with the --fix option.

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! /Users/zirinisp/.npm/_logs/2018-05-11T11_36_12_515Z-debug.log

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

My index.dart file is the following:

// Examples on: https://pub.dartlang.org/packages/firebase_functions_interop/versions/1.0.0-dev.4.0#-example-tab-

import 'dart:async';
import 'package:firebase_functions_interop/firebase_functions_interop.dart';

void main() {
  functions['createDocument'] = FirebaseFunctions.firestore.document('{collection}/{document}').onCreate(onCreate);
  functions['updateDocument'] = FirebaseFunctions.firestore.document('{collection}/{document}').onUpdate(onUpdate);
}

void helloWorld(ExpressHttpRequest request) {
  request.response.writeln('Hello world');
  request.response.close();
}

FutureOr<void> onCreate(DocumentSnapshot snapshot, EventContext context) {
  DocumentData newDocument = snapshot.data;
  String createdAtKey = "createdAt";

  // If there is a createdAt field already, return to avoid loops
  if (newDocument.getDateTime(createdAtKey) != null) return null;

  UpdateData newData = new UpdateData();
  DateTime now = new DateTime.now();
  newData.setDateTime(createdAtKey, now);

  return snapshot.reference.updateData(newData);
}

FutureOr<void> onUpdate(Change<DocumentSnapshot> change, EventContext context) {
  DocumentSnapshot snapshot = change.after;
  DocumentData updatedDocument = snapshot.data;
  DocumentData previousDocument = change.before.data;
  String updatedAtKey = "updatedAt";

  // If 'updatedAt' is different, that means we have already updated it
  if (updatedDocument.getDateTime(updatedAtKey) != previousDocument.getDateTime(updatedAtKey))
    return null;

  UpdateData newData = new UpdateData();
  DateTime now = new DateTime.now();
  newData.setDateTime(updatedAtKey, now);

  return snapshot.reference.updateData(newData);
}

Can you please help me out on how I can deploy.

pulyaevskiy commented 6 years ago

Sorry you're having issues. I'll look into this today and try to reproduce on my end. In the meantime could you provide output of following commands:

As well as contents of package.json and pubspec.yaml.

zirinisp commented 6 years ago

Thank you for the prompt reply.

The versions are the following:

dart --version Dart VM version: 2.0.0-dev.53.0 (Thu May 3 12:35:47 2018 +0200) on "macos_x64" node --version v9.5.0 firebase --version 3.18.4

package.json

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "firebase-admin": "~5.12.0",
    "firebase-functions": "^1.0.1"
  },
  "devDependencies": {
    "eslint": "^4.12.0",
    "eslint-plugin-promise": "^3.6.0"
  },
  "private": true,
  "main": "build/node/index.dart.js"
}

pubspec.yaml

name: surf_spotter_functions
description: My project functions
version: 0.0.1

environment:
  sdk: '>=2.0.0-dev <2.0.0'

dependencies:
  # Firebase Functions bindings
  firebase_functions_interop: ^1.0.0-dev

dev_dependencies:
  # Needed to compile Dart to valid Node.js module.
  build_runner: ^0.7.9
  build_node_compilers: ^0.1.0
pulyaevskiy commented 6 years ago

Thanks! Quick update: deploying Dart code you provided on my end worked fine.

I see that you have eslint in your devDependencies, wondering if it messes up something since all the errors in the output are lint checks.

pulyaevskiy commented 6 years ago

Do you have functions/.eslintrc.json file? Wondering if it'd work after you delete that file?

(There is no benefit in linting generated JS code)

pulyaevskiy commented 6 years ago

Just checking in here. Did you manage to resolve this issue? If so I'd be curious to know how you fixed it.

zirinisp commented 6 years ago

I installed the latest updates so my version are:

dart --version
Dart VM version: 2.0.0-dev.59.0 (Tue May 29 22:11:36 2018 +0200) on "macos_x64"
node --version
v9.5.0
firebase --version
3.18.5

I also removed .eslintrc.json

On firebase.json file I removed:

"predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint"
]

So the file looks like:

{
  "functions": {

  }
}

And my package.json file looks like:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "firebase-admin": "~5.12.0",
    "firebase-functions": "^1.0.1"
  },
  "devDependencies": {

  },
  "private": true,
  "main": "build/node/index.dart.js"
}

Now it deploys without problems.

Thank you very much for your help!!

pulyaevskiy commented 6 years ago

Awesome, thanks for getting back with the info! Closing this issue as resolved

AlexBacich commented 4 years ago

Also had the same issue and it was gone after .eslintrc.json removal. Maybe consider adding it into readme?