Why do bs-dependencies have to be in node_modules?

Hey all,

I’ve been trying to set up a ReScript project inside a monorepo powered by nx.dev.

I tried setting up a bsconfig.json

  "sources": [],
  "bs-dependencies": ["./libs/feature1"]

And then another bsconfig.json in the ./libs/feature1 directory

  name: "@app/feature1",
  sources: [{dir: "src", subdirs: true}, {dir: "test", subdirs: true, type: "dev"}]

This did not work as intended

File "bsconfig.json", line 1
Error: package ./libs/feature1 not found or built 
- Did you install it?
- If you did, did you run `rescript build -with-deps`?

So I thought to myself. What if I’m a bit cheeky and use a .. in the bs-dependencies. So I changed it to ../libs/feature1

This got me a bit further

File "/Users/user/path/to/repo/node_modules/../libs/feature1/bsconfig.json", line 2:
Error: package name is expected to be ../libs/feature1 but got @app/feature1

With this context I want to ask why bs-dependencies have to be in node_modules? Is it possible to change the system such that bs-dependencies take a Map instead of a list?

for this use case I could create something like:

  "bs-dependencies": {
    "@app/feature1": "./libs/feature1"

This would be a ReScript analog to the tsconfig.json paths property

1 Like

I had a similar problem with my library that isn’t ready to publish on NPM yet but I wanted to test it in an app that I am building. My workaround was to create a softlink of the dependency folder inside node_modules, which worked fine.

However, I’d prefer something like your proposal, maybe as an alternative syntax with explicit paths.

How did you end up solving this?

By the way, you can npm install dependencies directly from github repos without publishing them

Also can install local npm dependencies

it works with turborepo

FWIW I ended up having a single bsconfig.json in my repository. The compilation is fast enough that the entire repo compiles in less than a second and I bundle my code anyway so the fact that my bs.js files are using relative paths across projects in the repo doesn’t really matter all that much.

1 Like