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

Trailing slash breaks workspace features when yarn run inside workspace folder #5816

Open
j-maas opened this issue May 14, 2018 · 12 comments · May be fixed by #5826 or #8483
Open

Trailing slash breaks workspace features when yarn run inside workspace folder #5816

j-maas opened this issue May 14, 2018 · 12 comments · May be fixed by #5826 or #8483

Comments

@j-maas
Copy link

j-maas commented May 14, 2018

Do you want to request a feature or report a bug?

Bug.

What is the current behavior?
When the workspaces definition contains a trailing slash, running e. g. yarn workspaces info in the root works just as expected. But when you cd into the workspace folder and run yarn workspaces info, it fails because it cannot detect that that folder is a workspace.

If the current behavior is a bug, please provide the steps to reproduce.

  1. Create a new project directory.
  2. Create a subdirectory called package.
  3. yarn init inside package/.
  4. yarn init in the root.
  5. Add package/ (with trailing slash) as a workspace to the root package.json.
    ...
    "workspaces": {
      "packages": [
        "package/"
      ],
    },
    ...
    
  6. Run yarn workspaces info in the root. => Outputs workspace list correctly.
  7. Run yarn workspaces info in package/. => Fails with
    yarn workspaces v1.6.0
    error Cannot find the root of your workspace - are you sure you're currently in a workspace?
    info Visit https://yarnpkg.com/en/docs/cli/workspaces for documentation about this command.
    

What is the expected behavior?
Running yarn workspaces info should output the workspaces when run both inside root and package/.

If this behavior is intended, the documentation could reflect the reason why.

Please mention your node.js, yarn and operating system version.
Node v8.11.1
Yarn v1.6.0
Ubuntu 16.04 LTS

@ghost ghost assigned arcanis May 14, 2018
@ghost ghost added the triaged label May 14, 2018
@arcanis
Copy link
Member

arcanis commented May 14, 2018 via email

@j-maas
Copy link
Author

j-maas commented May 14, 2018

@arcanis I'm not sure if I'll have time, but in principle I'd like to try.

I'll write a new comment before I start, so that you know whether I'm working on this. Until then, if anyone would like to tackle this, go ahead.

@j-maas
Copy link
Author

j-maas commented May 14, 2018

I've started looking into it and I assume the root cause lies in micromatch or the arguments passed to it.

I will continue diggin for a bit.

@j-maas
Copy link
Author

j-maas commented May 14, 2018

This behaviour is reportedly supported in a newer version of micromatch.
The newest version is 3.1.10, whereas yarn is dependent on 2.3.11.

(It doesn't work in the newest version.)

I'm not sure how to add a test case for this bug. If you have any suggestions, I could try.

@j-maas
Copy link
Author

j-maas commented May 15, 2018

This is considered intended behavior micromatch. It thus should be handled in the call to the function.

@07Gond
Copy link

07Gond commented Oct 8, 2018

Hi, @arcanis & @BYK is this issue still relevant?

@thomassuckow
Copy link

thomassuckow commented Oct 16, 2018

Just ran into this in v1.10.1.

Edit: This explains why yarn add would create a yarn.lock in some workspaces but not others.

@joefiorini
Copy link

I also just ran into this issue in yarn v1.15.2. Crazy.

@forivall
Copy link

forivall commented Aug 3, 2019

I ran into what is probably the same issue, where instead of a trailing /, it was caused by a preceding ./

For example:

...
"workspaces": {
  "packages": [
    "./packages/*"
  ],
},
...

@simkessy
Copy link

Currently having this issue with this config:

    "workspaces": [
        "libs/common/client/",
        "services/app/client/"
    ]

At the root, I can find the packages.
But at the package level, it doesn't recognize it's part of a workspace. How do I fix this?

If I go to the package and add a dependency, it will create it in the packages node_modules instead of root.

@forivall
Copy link

@simkessy for now, the workaround is to change that to

    "workspaces": [
        "libs/common/client",
        "services/app/client"
    ]

@simkessy
Copy link

Wow, that was simple. This should be documented somewhere, wasted a lot of hours :(

Thanks @forivall !

sfsr12 pushed a commit to sfsr12/yarn that referenced this issue Dec 3, 2020
@sfsr12 sfsr12 linked a pull request Dec 3, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment