Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support workspaces without workspace: protocol #4676

Closed
raulfdm opened this issue Sep 9, 2023 · 11 comments
Closed

Support workspaces without workspace: protocol #4676

raulfdm opened this issue Sep 9, 2023 · 11 comments
Labels
bug Something isn't working bun install Something that relates to the npm-compatible client

Comments

@raulfdm
Copy link

raulfdm commented Sep 9, 2023

What version of Bun is running?

1.0.0+822a00c4d508b54f650933a73ca5f4a3af9a7983

What platform is your computer?

Darwin 23.0.0 arm64 arm

What steps can reproduce the bug?

While trying to migrate to bun workspace, I noticed that bun isn't able to resolve internal packages that contain organization alias.

Repository: https://github.com/devraul/bun-workspace-organization-error

Steps to reproduce:

  1. Clone the project
  2. Try to run bun install --yarn
  3. see the error
error: package "@monorepo/math" not found registry.npmjs.org/@monorepo/math 404
error: @monorepo/math@* failed to resolve

Notice that this only happens because I have @monorepo in the package name.

If you remove @monorepo and run the installation command, it will work fine.

What is the expected behavior?

Resolves the internal package with organization scope in its name.

What do you see instead?

CleanShot.2023-09-09.at.10.54.22.mp4

Additional information

Maybe related #4628

@raulfdm raulfdm added the bug Something isn't working label Sep 9, 2023
@benvan
Copy link

benvan commented Sep 9, 2023

@raulfdm I had the same problem, but have discovered a workaround / partial solution?

  1. Modify your dependency on "@monorepo/math": "*" to be "@monorepo/math": "workspace:*"
  2. Delete bun.lockb and try again (bun install)

The second step seems to be critical - if you don't, bun will instead give the following error (which does seem like a bug):

bun install v1.0.0 (822a00c4)


error: workspace dependency "@monorepo/math" not found

Searched in "./*"

Workspace documentation: https://bun.sh/docs/install/workspaces

EDIT: Seems I celebrated too soon. Whilst the installation works, bun can't resolve / import "@monorepo/math" at runtime

error: Cannot find module "@monorepo/math" from "/Users/ben/projects/bun-workspace-organization-error/test.ts"

EDIT 2: Ah. That's because in your example, the "@monorepo/math" package has an invalid config. It's looking for a file called "index.ts" in the package root but there isn't one

// in packages/math/package.json change this
"module": "index.ts"
// to this
"module": "src/index.ts"

@raulfdm
Copy link
Author

raulfdm commented Sep 9, 2023

Thanks for the inputs @benvan .

I've fixed the entry point in the demo repository.

Indeed, switching from * to workspace:* did the trick, but then we had to update the docs. It's misleading to the actual behavior. 🤔

is-it-ayush added a commit to typehero/typehero that referenced this issue Sep 9, 2023
the docs are misleading, checkout issue
oven-sh/bun#4676
@is-it-ayush
Copy link

Indeed, switching from * to workspace:* did the trick, but then we had to update the docs. It's misleading to the actual behavior.

Yep! Switching to workspace protocol fixed it. I wonder if the docs are either wrong or I missed a step. Either way, hope somebody from the team helps.

nvie added a commit to liveblocks/liveblocks that referenced this issue Sep 11, 2023
nvie added a commit to liveblocks/liveblocks that referenced this issue Sep 11, 2023
@colinhacks colinhacks changed the title Workspace does not install packages with organization (@) name Support workspaces without workspace: protocol Sep 12, 2023
@artberri
Copy link

Is switching from * to workspace:* just a workaround for now or the expected behavior? In our case, to be able to transition from node@20/yarn@1 to bun with baby steps we expect the package.json files to be compatible.

A good first approach for us could be to still run the app with node, but start running the unit tests with bun, but I think that this will not be possible unless the package.json syntax is compatible.

@dylang
Copy link
Contributor

dylang commented Sep 14, 2023

I created a PR to update the docs: #5379

@emanuel-lundman
Copy link

Shouldn't the issue be resolved to not need the workspace prefix instead. Better to fix the issue then alter the docs for the workaround? Or is it supposed to need the workspace prefix?

I know there were some other issue after adding the prefix. It helped to resolve the dependencies to get it running but everything doesn't work with the prefix either. Had some issue with another command not liking the prefix when I tried it in our monorepo.
Can't remember exactly which command it was but can absolutely try to find it again later.

@Electroid Electroid added the bun install Something that relates to the npm-compatible client label Oct 27, 2023
@Jarred-Sumner
Copy link
Collaborator

This bug was fixed in Bun v1.1.8:

 rm -rf node_modules ../../node_modules/ ../../bun.lockb
 bun-1.1.8 install
bun install v1.1.8 (89d25807)

 + @monorepo/math@workspace:packages/math
 + vite-project@workspace:apps/vite-project
 + bun-types@1.0.1 (v1.1.18 available)
 + typescript@5.2.2 (v5.5.3 available)

 84 packages installed [360.00ms]

 Blocked 1 postinstall. Run `bun pm untrusted` for details.

Bun v1.1.7 (where it did not work):

 rm -rf node_modules ../../node_modules/ ../../bun.lockb
 bun-1.1.7 install
bun install v1.1.7 (b0b7db5c)
  🔍 @monorepo/math [1/1]
error: package "@monorepo/math" not found registry.npmjs.org/@monorepo%2fmath 404
error: @monorepo/math@* failed to resolve

We've released 10 updates to Bun since Bun v1.1.8 and we've continued to make several improvements to workspaces support in bun install.

Let us know if you're still running into issues like this and we'll be happy to fix things.

@raulfdm
Copy link
Author

raulfdm commented Jul 6, 2024

@Jarred-Sumner thank you so much. Can confirm the problem is fixed :)

@Jarred-Sumner
Copy link
Collaborator

All credit to @dylan-conway :), I did almost nothing

@csmikle
Copy link

csmikle commented Aug 17, 2024

But is the requirement to use workspace: prefix still present today? Like others said I'm looking for package.json compatability and would just like to hear context about why it's needed.

Even with adding the prefix and changing imports I had issues moving a node project to Bun in July and would like to try again now... just wondering what may have improved on this front

@olistrik
Copy link

@csmikle I have a project with multiple workspaces, the only mention of them is in the root package.json where I declare the globs.

The sub-projects seem to resolve inter-project dependencies just fine even with semver ranges or an asterisk. bun pm ls lists the resolved dependencies with pathed versions such as foo@workspace:projects/bar".

My LSP even hops to definitions in the correct source files rather than to something in the node_modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bun install Something that relates to the npm-compatible client
Projects
None yet
Development

No branches or pull requests

10 participants