bun icon indicating copy to clipboard operation
bun copied to clipboard

Error with workspace dependency resolution when adding new packages

Open KryptXBSA opened this issue 9 months ago • 1 comments

What version of Bun is running?

1.1.7

What platform is your computer?

Linux 6.8.0-76060800daily20240311-generic x86_64 x86_64

What steps can reproduce the bug?

  1. clone the workspaces example repo https://github.com/AlandSleman/bun-workspace-issue
  2. create a new package
  3. add the new package as a dependency for any other packages and run bun install

What is the expected behavior?

All workspace dependencies, including newly added packages, should be correctly resolved and installed without errors.

What do you see instead?

Instead of the expected smooth dependency resolution and installation, the following issues are observed:

  1. After running bun install An error message indicating that the workspace dependency @oven-sh/c is not found, despite it being correctly defined in the package.json of another package within the workspace.

    error: workspace dependency "@oven-sh/c" not found
    Searched in "./*"
    
  2. After running bun install --verbose a verbose log message suggesting an issue with file operations, specifically mentioning difficulties with moving files from a temporary directory due to restrictions across mount points:

    info: cannot move files from tempdir: RenameAcrossMountPoints, using fallback
    

These issues suggest problems with Bun's handling of local workspace dependencies and potentially its file system operations in certain environments, leading to unsuccessful installations and unresolved dependencies.

Additional information

A repository demonstrating the issue: https://github.com/AlandSleman/bun-workspace-issue

  • This issue persists even after deleting lock files and trying to reinstall dependencies. I have encountered this problem multiple times while working with Bun workspaces, indicating a recurring issue under certain conditions.
  • Sometimes, deleting lock files and reinstalling dependencies has resolved the issue, but it does not consistently fix the problem.

KryptXBSA avatar May 07 '24 07:05 KryptXBSA

After diving deeper, I think the issue is with the * wildcard, after explicitly specifying the workspaces/packages in the package.json.

So instead of using:

  "workspaces": [
    "packages/*",
    "apps/*"
  ],

You could specify:

  "workspaces": [
    "apps/backend",
    "packages/backend-api"
  ],

After explicitly defining packages and installing the packages, the * wildcard does work correctly for including all packages and apps. I'm keeping this issue open because there could be an underlying issue with the * wildcard when configuring packages/workspaces, I also think it involves caching. Please correct me if I'm wrong.

KryptXBSA avatar May 07 '24 11:05 KryptXBSA

Fixed in #11177 and available in canary (bun upgrade --canary to update). Please reopen this issue if you continue to have problems with workspaces, or open a new one.

dylan-conway avatar May 24 '24 07:05 dylan-conway