BuckleScript library exposing another


#1

I have one BuckleScript library/module X that depends on another Y. The module Y should be exposed by X (i.e. x.ml contains the line module Y = Y and has library Y as a dependency in package.json and bsconfig.json). But Y isn’t visible to projects that depend on X – attempting to compile them gives The module X.Y is an alias for module Y, which is missing. How can I fix this?

One thing I tried was replacing module Y = Y with module Y = struct include Y end. This kind of works, but it doesn’t seem to include the submodules for Y – I get the same error message about the module X.Y.Z. And it doesn’t seem like the right thing to do anyway.


#2

Let’s call Z the project that uses X. So, in Z, if you add both X and Y as dependencies in bsconfig.json, does the error go away?


#3

That error goes away but I get another stranger one saying that x.cmi and y.cmi “make inconsistent assumptions over interface I”, where I is a library that is only used in X via the dependency on Y (which uses I directly).


#4

Does this error go away on a clean build of Z:

npx bsb -clean-world
npx bsb -make-world

#5

It does initially, but then when I run npm install && npm start although the first build works I get the error as soon as I trigger a rebuild (even if it’s just writing a file without changes).


#6

What does the npm start command run?


#7

bsb -make-world -w -ws _ (the default for a react-hooks project)


#8

So in my experience running bsb -make-world with every code change tends to screw up the intermediate compiled files. Can you try with bsb -w -ws _ instead? I.e. only run bsb -make-world if some dependencies actually change.


#9

Thanks, interesting! But sadly the same thing happens with that.


#10

Interesting … so the build succeeds the first time round but fails subsequently. It would be good to have a minimal repro example of this to play with.


#11

So I put together an example, and for some reason switching from local copies of libraries to npm registry ones solved it! Not really sure why that happened, but I’m not complaining. If you’re interested, the project was porting ppx_yojson_conv to BuckleScript.