samuelgozi/firebase-firestore-lite

Runtime error when using with require-so-slow module

Closed this issue ยท 11 comments

I see an error when running with require-so-slow module which is usually used to profile cold starts.
I have no clue what is causing the issue and would be great if you can help.

node_modules/firebase-firestore-lite/dist/mod.js:1
(function (exports, require, module, __filename, __dirname) { import { Database } from './Database.js';
                                                                     ^

SyntaxError: Unexpected token {
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at perfTrace.wrap (/functions/node_modules/require-so-slow/build/src/shim.js:18:28)
    at Object.wrap (functions/node_modules/require-so-slow/build/src/perf-trace.js:37:16)
โš   We were unable to load your functions code. (see above)
   - You may be able to run "npm run build" in your functions directory to resolve this.

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.73. Please mark this comment with ๐Ÿ‘ or ๐Ÿ‘Ž to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

Seems like the error is not just specific to this module alone. Please check a similar issue here.

โš   /functions/node_modules/firebase-firestore-lite/dist/mod.js:1
(function (exports, require, module, __filename, __dirname) { import { Database } from './Database';
                                                                     ^

SyntaxError: Unexpected token {
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
โš   We were unable to load your functions code. (see above)

Also I see something strange. The .js files in dist folder are still having ts code and didn't transpile.

If I had to guess I would say its a build/transpilation related issue.
I'll take a look at it.

Edit: I'm 99% confident it's a transpilation issue.
In this library, I use some very recent JS features, and I don't transpile it. That's up to the developer.
Make sure you configure your build tool so that it transpiles node modules.

I'm sorry I can't give a more specific solution, but I couldn't find any info on the require-so-slow repo, and I've never used it before.

Unfortunately its unusable right now :|
I uninstalled require-so-slow and still its throwing up the above error.

Let me see If I can find a solution. I'm using it with nodejs + firebase-admin + cloud functions. Also, i downloaded the project repo separately and found out that its not transpiling to js code when i generate the dist files.

Ok, I realize now that its not made for using as a replacement for node-firestore project but from a browser perspective. That could be the reasons why its giving me errors with permission when requesting.
Do you have any suggestions?

Yes it is made to be used on the browser.
You can use it from node, but you will have to transpile it with babel to your Node target, as well as provide a Fetch Polyfill.

You need to take into consideration that at the moment there is no built-in way to log in as admin, and I wouldn't recommend to use it as a replacement for firebase admin at this point in time(although I am working on something to make this possible)

Thanks for confirming.
I'm trying to use googleapis for getting the access token and add it to headers from service account.

For fetch I used node-fetch module.
Incase if you have a solution, please let me know.

The main issue with the library right now is that it lacks many of the features needed for administration.
And also, there isn't a built-in way of managing tokens that come from the service account API.
So I would really recommend you use the official admin SDK.

I have a very bare-bones admin API in a private repo, but since it lacks functionality, and wasn't tested thoroughly I haven't released it yet.
I plan to release it when the Deno runtime adds a crypto library, and I believe it will be relatively easy to port to node then.

Thanks Samuel.
I was able to make it work. May be I will fork your library and commit separately as I can't get a compatibility with this library due to known reasons (missing default expected libraries like crypto, fetch etc). Also, auth lite is not something that can be easily pulled in, so using google jwt auth internally for access tokens.

Thanks a lot for the great library. It's super clean :)

Thank you for trying it out!