Rescript-compiler: Relative import paths from other file modules are not correctly generated.

Created on 18 Aug 2018  路  4Comments  路  Source: rescript-lang/rescript-compiler

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

stale

Most helpful comment

@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

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

glennsl picture glennsl  路  3Comments

wyze picture wyze  路  3Comments

tanaka-de-silva picture tanaka-de-silva  路  5Comments

TheSpyder picture TheSpyder  路  5Comments

bobzhang picture bobzhang  路  4Comments