Consuming your own ReScript Library in ReScript

I created a library; has a bunch of modules in src. I publish to my internal Nexus.

In another ReScript project, I npm install it, and add it to the bsconfig.

… however, it can’t seem to find all modules. The compiler gives me that message like:

The module or file ProductTypesV3 can't be found.
- If it's a third-party dependency:
  - Did you list it in bsconfig.json?
  - Did you run `rescript build` instead of `rescript build -with-deps`
    (latter builds third-parties)?
- Did you include the file's directory in bsconfig.json?

The ProductTypesV3 is in the library I published, and other files use it, and I confirmed it’s in node_modules. It appears some of the code is found, and out of paranoia I tried npm run clean but the only thing that seems to make it happy is instead of just running:
"start": "rescript build -w",

I tried:
"builddeps": "rescript build -with-deps -w",

… and THAT seems to find things. Is this how I should be working with ReScript libraries? How come the @ryyppy/rescript-promise library works fine and mine doesn’t?

As I scroll down, I’m noticing that the errors imply it does know about that module; I’m wondering if I should just ignore the Problems tab in VSCode, and focus on the obvious compiler errors in the Terminal, THEN back track to the Problems tab and see if they’re resolved by that point. Typically the Problems tab has been dead on; this is the first time it’s giving me mixed results.

… ok, fixed a bunch, but it’s still failing to find various Modules (both IDE errors and compiler). The worst part is the compiler says it has a bug as I comment most of the code out, but doesn’t show any actual compiler errors… This is so weird.

1 Like

are you using any monorepo tooling?
did you specify an entry file in package.json and had that entry file point to all the modules that you want to expose?

Naw, no monorepo, just normal ReScript / Node.js template stuff. Naw, I just defaulted package.json main to index.js to mirror what the Promise library has.

I’ve taken the tactic now to comment ALL code out and slowly bit by bit uncomment each line by line and it seems to be working. Some were calling theFunction vs Module.theFunction; silly things like that were confusing the eff out of the compiler which is fine, progress…

For posterity, offending return value type hint confused the compiler, and me, for about 80% of the errors. A bit sad I was getting the “can’t find module” errors first as it was completely false, but all good. Pretty brutal refactoring I was doing so I knew what I was in for.

1 Like