Hi!
I was just testing bun with rescript 12 RC in a monorepo setup, did the workspaces in package.json, listed the package dependencies in the root rescript.json and got this error when building:
We could not build package tree reading dependency 'starter', at path '<redacted>'. Error: try_package_path: upward traversal did not find 'starter' starting at '<redacted>'
Just wanted to share, by default bun uses isolated installs like pnpm I believe, and it wasn’t creating symlinks to the workspace packages in node_modules, which rescript 12 (rewatch) needs.
To solve this in an automated way (no manual symlinks) and without changing the bun linker to hoisted, I decided to add the packages to the dependencies in the root package.json like so:
"dependencies": {
"starter": "workspace:*"
},
Which then when bun install it will make a symlink from the root node_modules/starter to the packages/starter folder. Then rescript works just fine.
Just sharing in case anyone else hits this issue or someone has other solutions. Here is a summary of how it looks like:
ReScript Monorepo Setup with Bun Workspaces
Directory Structure
.
├── bun.lock
├── package.json
├── rescript.json
└── packages
└── starter
├── package.json
├── rescript.json
└── src
├── Demo.res
└── Demo.res.mjs
Root package.json
{
"name": "monorepo",
"private": true,
"workspaces": {
"packages": [
"packages/*"
],
"catalog": {
"rescript": "^12.0.0-rc.3"
}
},
"scripts": {
"build": "rescript build",
"clean": "rescript clean",
"dev": "rescript watch",
"format": "rescript format -all",
},
"dependencies": {
"@monorepo/starter": "workspace:*"
},
"devDependencies": {
"rescript": "catalog:"
},
}
Root rescript.json
{
"name": "monorepo",
"sources": [],
"package-specs": {
"module": "esmodule",
"in-source": true
},
"suffix": ".res.mjs",
"dependencies": ["@monorepo/starter"],
"compiler-flags": []
}
Package package.json (packages/starter/package.json)
{
"name": "@monorepo/starter",
"version": "0.0.0",
"description": "ReScript starter package",
"main": "src/Demo.res.mjs"
}
Package rescript.json (packages/starter/rescript.json)
{
"name": "@scope/starter",
"sources": {
"dir": "src",
"subdirs": true
},
"package-specs": {
"module": "esmodule",
"in-source": true
},
"suffix": ".res.mjs",
"dependencies": [],
"compiler-flags": []
}
Adding New Packages
- Create directory in packages/new-package/
- Add to root package.json dependencies:
"@monorepo/new-package": "workspace:*" - Add to root rescript.json dependencies:
["@monorepo/new-package"] - Run bun install to create symlinks
And a couple of links that helped me out:
Let me know how y’all do it!