pulyaevskiy / firebase-functions-interop

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

Deployment error #35

Closed kostaa closed 5 years ago

kostaa commented 5 years ago

Getting this error during the deployment. Not sure if this is a Firebase issue or the generated code is invalid. When I googled this found somewhat similar problems that were resolved by downgrading the Firebase tools versions.

image

These are two functions that I am deploying. However when I remove the 'applySystemPayeeRules' method and the dependency on the the library where this is implemented all is good. So this makes me think that maybe the generated code is not quite right.

image

Here is the 'index.dart.js' if that helps. index.dart.js.zip

pulyaevskiy commented 5 years ago

Could you also provide following?

  1. Dart SDK version (dart --version)
  2. Node.js version (node --version)
  3. Firebase tools version (firebase --version)
  4. Contents of package.json
  5. Contents of pubspec.yaml

This would help in investigating your issue.

The minified index.dart.js is not much of a help here, unfortunately.

kostaa commented 5 years ago

Dart VM version: 2.0.0 (Fri Aug 3 10:53:23 2018 +0200) on "windows_x64" Node version: v8.12.0 Firebase version: 5.1.1

package.json
{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "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": "^6.0.0",
    "firebase-functions": "^2.0.5"
  },
  "private": true,
  "main": "build/node/index.dart.js"
}
pubspec.yaml

name: mv_cloud_functions
version: 1.0.0

environment:
  sdk: '>=2.0.0 <3.0.0'

dependencies:
  firebase_functions_interop: ^1.0.0-dev
  system_payee_rules:
    path: ../lib_sys_payee_rules

dev_dependencies:
  build_node_compilers: any
  build_runner: any
  test: any

These are the actual versions

firebase_functions_interop: "1.0.0-dev.10.0" build_node_compilers: "0.2.0" build_runner: "1.0.0"

kostaa commented 5 years ago

Hi @pulyaevskiy, have you had time to have a look into this?

pulyaevskiy commented 5 years ago

Hey, it's a bit hard to reproduce this error on my end giving available information.

I suspect that there is some code in lib_sys_payee_rules which causes this issue. If there is any way you can compose a reduced test case, this would help significantly.

kostaa commented 5 years ago

The lib_sys_payee_rules library has dependencies on some other libraries (eg quiver) and I am currently writing another cloud function that will need dart:convert library and maybe some others.

In your examples you seem to use only the underlying Firestore javascript libraries. I am trying to be careful when bringing in additional dependencies but it would be good to know the limitations - what is allowed and what is not.

pulyaevskiy commented 5 years ago

In general, with JS interop you can't use dart:io or any package which depends on dart:io because this library is only available in the Dart VM. That's the main limitation.

For this reason I've also created node_interop and node_io packages. Nice thing about node_io is that it wraps Node.js I/O using the same interfaces you normally use in dart:io, so you get Futures and Streams for free. Note though that I've only implemented a portion of dart:io interfaces (most FS classes, HttpServer), so if you end up needing a method which throws UnimplementedError feel free to submit an issue here: https://github.com/pulyaevskiy/node-interop/issues.

If you need to make an HTTP request I'd also recommend node_http which implements HttpClient interface from http package.

Other built-in libraries like dart:convert can be used without any issues.

kostaa commented 5 years ago

Great that is good news. I will try and narrow it down to the piece of code that is causing the issue.

kostaa commented 5 years ago

Managed to find the issue. One of the libraries that I was bringing in contains a class that imports the dart:io library. All works as expected once I removed this class from the library.

However this class is not used by any of the classes reachable from the cloud functions I am deploying. Since is not reachable I would expect that it is not included in the compiled JavaScript code.

pulyaevskiy commented 5 years ago

Great you resolved this!

Since is not reachable I would expect that it is not included in the compiled JavaScript code.

I would expect the same. Is it an open source library from Pub? Would be nice to understand why it causes issues.

kostaa commented 5 years ago

No these are all my libraries. I will try an reproduce this in a small project.

pulyaevskiy commented 5 years ago

Ok, no worries. I'll close this for now, but feel free to send updates if you find something interesting.

kostaa commented 5 years ago

Just to let you know that I have not managed to reproduce this. Looks like I had my wires crossed somewhere in the original implementation.

pulyaevskiy commented 5 years ago

Good to know, thanks for getting back on this.