Package import "Diamond Problem" and building dependencies

Hi All
So I now have a package that is our core lib. I am using this package as both a first-order and second-order dependency in our application (We have it in dependencies, and we have a dependency that has it as a dependency). When I build I see a log:

Duplicated package: @nobleai/rescript-prelude /code/noble-sl/web/node_modules/@nobleai/rescript-prelude (chosen) vs /code/noble-sl/web/node_modules/@nobleai/rescript-fields/node_modules/@nobleai/rescript-prelude in /code/noble-sl/web/node_modules/@nobleai/rescript-fields 

which seems to suggest it takes the immediate dependency and doesnt build the second-order dependency? If i look in node_modules directory rescript-fields I dont see the dependencies built.

Then I run some code in my tests that exercises rescript-fields that crashes:

 FAIL  src/components/Objective.test.bs.js [ src/components/Objective.test.bs.js ]
Error: Failed to resolve import "@nobleai/rescript-prelude/src/Map.bs.js" from "node_modules/@nobleai/rescript-fields/src/UseField.bs.js". Does the file exist?

So, is there something to be done to alias those imports when one build of a project is picked and the other is skipped?

TIA
A

1 Like

Do you have - by any chance - different versions of the same package installed?

Wha’ts the result of npm ls @nobleai/rescript-prelude?
Are you even using npm? (or yarn? pnpm?..)


Did you change a dependency (e.g. npm install / update) while watch of the compiler was running or similar?
Does the issue persist if you run rescript clean and build afterwards again?

[nix-shell:~/noble-sl/web]$ npm ls @nobleai/rescript-prelude
noble@0.0.1 /noble-sl/web
├─┬ @nobleai/rescript-fields@0.1.4
│ └── @nobleai/rescript-prelude@0.12.3
└── @nobleai/rescript-prelude@0.12.4

Aha! unifying the versions has done it. Still it seems like something rescript should be able to handle if we’re going to be serious about an expansive library ecosystem?

Thanks @woeps

Alex

The current state is, that modules are identified by name (globally), and there is no notion of versions.
Therefore the compiler doesn’t really know what to, when there is the same Module present twice.

You can try a similar issue easily by creating two directories and creating a rescript file with the same name in both directories.