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

[Blocking] Generated .bs.js code references a function that was not imported #6018

Closed
jmagaram opened this issue Feb 28, 2023 · 4 comments
Closed

Comments

@jmagaram
Copy link
Contributor

jmagaram commented Feb 28, 2023

=== UPDATED ===

See this playground

I can't run my project because code I import into TypeScript doesn't work.

=== UPDATED ===

The generated code does not work; some kind of import problem, maybe related to genType. There is a much simpler repro scenario in https://github.com/jmagaram/rescript-issues

Look at Firebase2Consumer.bs.js - notice the call to getFirestore, a function that is not imported.
Look at Firebase2.bs.js - notice the call to getFirestore, a function that should appear as Firebase2Gen.getFirestore

Adding a .resi file seems to fix it.

=== ORIGINAL POST ===
I'm writing some bindings for Firebase. The generated code does not run because of problems with imports/exports. rescript": "^10.1.2" I created a vite Rescript app and added 2 files.

https://github.com/jmagaram/rescript-issues

Look at the code generated in UseFirebase.bs.js. Notice the getFirestore function; it is not imported from anywhere. It should have been exported from Firebase.bs.js but is not. As I look closer at Firebase.bs.js I see tons of problems. It references functions like connectFirestoreEmulator but SHOULD reference FirebaseGen.connectFirestoreEmulator. Is this a genType issue?

// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Firebase from "./Firebase.bs.js";

var liveOptions = {
  apiKey: "AIzaSeDzEyIOOVDG4IMWnwlUgvuYSXOCk_ZGaOg",
  authDomain: "admin-panel.firebaseapp.com",
  projectId: "admin-panel",
  storageBucket: "admin-panel.appspot.com",
  messagingSenderId: "845699356146",
  appId: "1:845699356146:web:a28bc650144ac4a9e2876b",
  measurementId: "G-L87PBG6ZXD"
};

var app = Firebase.FirebaseApp.make(liveOptions);

var store = getFirestore(app);

export {
  liveOptions ,
  app ,
  store ,
}
/* app Not a pure module */
@jmagaram jmagaram changed the title Generated .bs.js code references a function that was not exported/imported [Blocking] Generated .bs.js code references a function that was not imported Feb 28, 2023
@jmagaram
Copy link
Contributor Author

I created a new project using the ReScript template. I added a couple bindings for Firebase and the code doesn’t look like it will work.

simple project

If you look at UseFirebase.ts you see it imports from ./FirebaseBindings.gen.

In FirebaseBindings.gen you’ll see a require... which I don’t understand since I configured it for es6. Why is there the require syntax?

In FirebaseBindings.bs you’ll see a call to getFirestore which SHOULD BE a call to FirebaseBindingsGen.getFirestore. This call will never work and in my real app I was getting a runtime error about that function not existing.

@cristianoc
Copy link
Collaborator

cristianoc commented Mar 1, 2023

Try genType.import instead of @gentype.import.
There's some work done in the compiler that is not case insensitive.

For the require, it's a complexity due to the recursive dependency between the .bs.js and .gen.tsx files when both an import and an export are present in the same file.
E.g. here:

@genType.import("foo/bar")
external aaa : string => string = "aaa"

@genType
let bbb = 10

But it does not happen here:

@genType.import("foo/bar")
external aaa : string => string = "aaa"

So you might want to re-arrange your files if that's a problem.

@jmagaram
Copy link
Contributor Author

jmagaram commented Mar 1, 2023

OMG. I never would have figured this out and it was totally blocking me. I'm surprised there are no warnings or errors for annotations that aren't recognized. Thank you.

@cristianoc
Copy link
Collaborator

All the annotations that are not recognised would need to give warnings. And different annotation processors recognise different annotations. So that would require some sort of global coordination.
There's currently no mechanism for an annotation processor to specify what annotations it has recognised. Though it would be good to have.

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