Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: regeneratorRuntime is not defined #1

Closed
samtstern opened this issue Mar 5, 2018 · 4 comments
Closed

ReferenceError: regeneratorRuntime is not defined #1

samtstern opened this issue Mar 5, 2018 · 4 comments

Comments

@samtstern
Copy link
Contributor

samtstern commented Mar 5, 2018

I work on Firebase and I wanted to add your awesome library to our firebase/snippets-rules github repository. I am running into a strange error, hoping you can help (I'm not a JavaScript expert at all so excuse me if this is totally user error).

I am trying out this library and decided to run a basic test:

import * as expectFirestore from 'expect-firestore';

const database = expectFirestore.Database({
  credential: {},
  data: {},
  rules: ''
});

// Note: doesn't matter if this function is async or not, or if I await the promises or not
async function main() {
  database.authorize();

  // Test a get
  database.canGet({ uid: 'some-user' }, 'users/userA');
}

main();

When I run it, this errors:

$ ts-node test/index.ts

/usr/local/google/home/samstern/Projects/firebase/snippets-rules/node_modules/expect-firestore/lib/global.js:37
}();
 ^
ReferenceError: regeneratorRuntime is not defined
@SamyPesse
Copy link
Member

SamyPesse commented Mar 5, 2018

This error usually come from babel when the polyfill for async/await has not been included. Requiring babel-polyfill in your script should fix it.

But I'm not sure how it works with ts-node.

I wanted to add your awesome library to our firebase/snippets-rules github repository

Thank you, I've built this library because our application has more than 1000 unit tests concerning our RTDB security rules, but we are not yet using Firestore and this library for our application, because we cannot switch to Firestore while it doesn't support validating batch updates / transactions.

I really hope Firebase would focus the next releases of Firestore on:

  • Improving the writing of security rules, current language is not very good for typing the data (see Bolt for Cloud Firestore FirebaseExtended/bolt#216), Efforts like protobuf-rules-gen are more hacking than real solutions
  • Release a local emulator for security rules (that do not require sending a lot of mocked data and our rules to a remote server for each assertion)
  • Fix the batch update validation
  • Document and help developers write reliable and secure rules for their DBs, I'm ready to bet that 90% of applications built on top of Firestore have important security flaws, not because of Firebase as a platform itself but because it's poorly documented how to write secure application (almost all of your sample have "write and read everything" rules)

That being said, we love the idea of Firebase ❤️, Firestore looks like an amazing solution in theory, but it's really frustrating to invest in a tool that look mostly focused on prototypes and small projects. We sometimes feel like we are the only company trying to build a well-tested, secure application on Firebase..

@samtstern
Copy link
Contributor Author

@SamyPesse first of all thank you for your feedback on Firestore. I hear you and I will make sure others do as well.

As for this bug:

  • I am not using Babel at all in my project
  • This appears with JS and plain-ol node as well as with TypeScript and ts-node
  • I have added babel-polyfill to my project and done require('babel-polyfill') in my code with no success

@SamyPesse
Copy link
Member

first of all thank you for your feedback on Firestore. I hear you and I will make sure others do as well.

Thanks, As I've told @mcdonamp as well, we will be happy to help alpha/beta test or even contribute writing tooling to fix these issues.

As for this bug

This library is compiled with babel, and it's not advised by babel to add the polyfill for async and generator functions in each libraries (it should be in the app/script using the library).

The polyfill should be included before anything else. If you use import calls, Typescript will probably compile these imports (statics) before any require calls (runtime).

Try import 'babel-polyfill'; as the first line of your script.

This "works" for me:

import 'babel-polyfill';
import * as expectFirestore from 'expect-firestore';

const database = new expectFirestore.Database({
  credential: {},
  data: {},
  rules: ''
});

// Note: doesn't matter if this function is async or not, or if I await the promises or not
async function main() {
  await database.authorize();

  // Test a get
  await database.canGet({ uid: 'some-user' }, 'users/userA');
}

main();

It outputs:

ts-node ./test.ts
(node:51554) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: No key or keyFile set.
(node:51554) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

@samtstern
Copy link
Contributor Author

@SamyPesse now I get it, thanks! I had to follow your advice and nuke my node_modules. Apologies for the noise, I don't leave my Android bubble often enough.

bfirsh added a commit to bfirsh/expect-firestore that referenced this issue May 29, 2018
sdumetz added a commit to sdumetz/expect-firestore that referenced this issue Jun 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants