My directory structure is
some-library.js
OuterModule.re
components/ComponentModule.re
In OuterModule.re I do:
[@bs.module "./some-library" external someFunction: (data) => unit = ""
and in ComponentModule.re I use the imported function:
OuterModule.someFunction(data)
However, the generated ComponentModule.bs.js has
import * as SomeLibrary from "./some-library";
but since this is relative to the components/ directory, it will error.
I think this is unintuitive, and ComponentModule.bs.js should import relatively from OuterModule.bs.js instead.
bs-platform: 3.1.5
hi, in general relative path is not recommended in the FFI, that is something we want to fix in the future. Would adding a line below fix the issue?
[@bs.module "./some-library" external someFunction: (data) => unit = ""
let someFunction: (data) => unit ;
Doing that does fix it, but it seems unintuitive as typically things defined in a particular scope are available to any other module that has access to that scope.
To clarify, when a JS function is imported via the FFI the recommendation is not to use it in any other modules, i.e. we shouldn't treat the "external" keyword as a let binding?
@zhzhang , in general, it is recommended to bind third party libraries
[@bs.module "some-library" external someFunction: (data) => unit = ""
so it is okay in this case, I understand your use case, we should have it documented and propose a fix, a simple fix is when we noticed a relative path in the bs.module, we don't inline such bindings
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
@zhzhang , in general, it is recommended to bind third party libraries
so it is okay in this case, I understand your use case, we should have it documented and propose a fix, a simple fix is when we noticed a relative path in the
bs.module, we don't inline such bindings