rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Pinned and Dev dependencies interacting

Open CarlOlson opened this issue 1 year ago • 1 comments

This is hard to explain, so here is a reproducible example. The names of workspaces and modules were chosen to somewhat reflect the project I discovered this in. This was confirmed on version 10.1.2 and 11.0.1.

If you have 3 workspaces W_root, W_a, and W_b. W_root adds the two others as pinned dependencies. W_a and W_b both contain a dev directory with some module M. If W_a includes W_b as a dev dependency, then opens W_b, then W_b.M will collide with W_a.M when used.

Snippet from the example repo's output:

FAILED: test/MainTest-SrcHelpers.cmj

  We've found a bug for you!
  <removed>/rescript-shadow-test/src-helpers/test/MainTest.res:4:14-23

  2 │
  3 │ let _ = Helper.setup()
  4 │ let config = Config.get()
  5 │

  The module or file Config can't be found.
  - If it's a third-party dependency:
    - Did you add it to the "bs-dependencies" or "bs-dev-dependencies" in bsconfig.json?
  - Did you include the file's directory to the "sources" in bsconfig.json?


  Hint: Did you mean Config or Config?

What do I expect?

  • I expect the modules in a "type": "dev" directory to never collide when building a different project.
  • I expect the error message to be more helpful. Perhaps the hint should use the full module path: Hint: Did you mean SrcHelpers.Config or TestHelpers.Config? (this wouldn't fix the problem, but would have made discovering the cause easier)

CarlOlson avatar Mar 15 '24 08:03 CarlOlson

@CarlOlson thanks for the detailed report and reproduction! 🙏

There's some ongoing work related to this "behind the scenes" currently. Hopefully this and more things related to pinned dependencies will clear up a lot in the not too distant future.

Maybe one of our monorepo users has some insight already. Cc @tsnobip @fhammerschmidt

zth avatar Mar 15 '24 09:03 zth

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.

github-actions[bot] avatar Mar 11 '25 02:03 github-actions[bot]

@CarlOlson is this a problem in Rewatch as well?

zth avatar Mar 11 '25 05:03 zth

@CarlOlson is this a problem in Rewatch as well?

No, but only because Rewatch doesn't compile "type": "dev" sources. There is an open issue: https://github.com/rescript-lang/rewatch/issues/124

CarlOlson avatar Mar 11 '25 05:03 CarlOlson