yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.45k stars 2.73k forks source link

Getting "Workspaces can only be enabled in private projects" even for a private project #8580

Closed kaiyoma closed 1 year ago

kaiyoma commented 3 years ago

I'm using yarn + lerna in a mono-repo, and today, after rebuilding my lockfile, I started seeing this warning from yarn:

[3/4] Linking dependencies...
warning Workspaces can only be enabled in private projects.

I'm not sure why I'm seeing this because I have this in my package.json:

  "private": true,

Seems like a bug in yarn?

Node 14.15.0 yarn 1.22.5 lerna 3.22.1

gabegorelick commented 3 years ago

I'm seeing this warning in a public project that does not use workspaces.

rally25rs commented 3 years ago

Could you provide a minimal package.json to reproduce the issue?

IanMayo commented 3 years ago

Possible duplicate of: https://github.com/webpack/webpack-cli/issues/479

bkglobal commented 3 years ago

In package.json add the directory in workspace like

"workspaces": [
      "app/*"
]
gabegorelick commented 3 years ago

Possible duplicate of: webpack/webpack-cli#479

In my case, the issue is indeed caused by a dep that has workspaces set (although not webpack-cli in my case).

Seems like yarn should either tell you the offending package, or just not warn at all if a dep erroneously has workspaces set.

kennie-larkson commented 3 years ago

I am having this same warning in a project that does not use workspaces upon yarn add moment and I have ‘private’: true in package.json

eps1lon commented 3 years ago

At this point it shouldn't warn about this in dependencies at all. The dependencies might be using a package manager that uses that field differently. For example, in yarn v2 using workspaces in a published package is perfectly fine:

Worktrees used to be required to be private (ie list "private": true in their package.json). This requirement got removed with the 2.0 release in order to help standalone projects to progressively adopt workspaces (for example by listing their documentation website as a separate workspace).

-- https://yarnpkg.com/features/workspaces#how-to-declare-a-worktree

For us, we get the warning since we have react-redux installed. But react-redux is setup correctly from their viewpoint. So the warning is not actionable.

kaiyoma commented 3 years ago

See also https://github.com/reduxjs/react-redux/issues/1815

mjstelly commented 3 years ago

For us, we get the warning since we have react-redux installed. But react-redux is setup correctly from their viewpoint. So the warning is not actionable.

So, do you mean that it's likely a false positive? I'm new to workspaces and my current project uses them with Yarn Classic. But I question whether they have been set up correctly due to other problems I found. I can't determine if this warning arises from something I did, or the existing project itself. It actually displays 3 times

Error running 'yarn install (if yarn is installed)': warning Workspaces can only be enabled in private projects.
Error running 'yarn install (if yarn is installed)': warning Workspaces can only be enabled in private projects.
Error running 'yarn install (if yarn is installed)': warning Workspaces can only be enabled in private projects.
benquarmby commented 2 years ago

NPM says hello and a friendly "up yours" to the only-private-packages-have-workspaces rule 👋

ale917k commented 2 years ago

It's been a year and a half since raised; Has anything been done or discussed about this? Can the warnings at least be omitted when flagged on dependencies? Bit annoying to have all these around..

Screenshot 2022-07-30 at 16 40 57

nhhockeyplayer commented 2 years ago

its gotten worse on node v18 can no longer install even if you toggle their property on or off

meanstack02@admin meanstacknh % yarn install
yarn install v1.22.19
error Workspaces can only be enabled in private projects.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

build is now blocked no wait its now working after waiting 5mins... must be all the arcane hidden ".cache" folders dispersed everywhere in $home and beneath node_modules

these institutions are in over their head and the frustration is a group failure altogether mismanaged it all started with npmjs.org which is still collecting credit card subscriptions and nothing works like a real software project should

hopefully microsoft will fix everything

gduliscouet-ubitransport commented 2 years ago

@rally25rs @merceyz Here is a minimal reproduction package.json of the issue (just installing semantic-release revealed this unwanted warning):

{
  "name": "yarn-warning-repro",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "private": true,
  "dependencies": {
    "semantic-release": "^19.0.3"
  }
}

image

yarn version 1.22.19 node version 16.14.0

A repository of the reproduction: https://github.com/gduliscouet-ubitransport/yarn-warning-repro

rally25rs commented 2 years ago

thanks for the repro case @gduliscouet-ubitransport

It looks like one of the transitive deps is npm

semantic-release > @semantic-release/npm > npm

The npm package's package.json indicates it is a workspace

{
  "version": "8.17.0",
  "name": "npm",
  "description": "a package manager for JavaScript",
  "workspaces": [
    "docs",
    "smoke-tests",
    "workspaces/*"
  ],

which is what is leading to this warning.

Since this is just a warning I think it can be ignored; the npm library still does get installed into node_modules

guillaumeduliscouet commented 2 years ago

Thank you @rally25rs for analysing this, Can we close this issue/subject with a clear conclusion ? I see 2 possibilities:

1. This "workspaces should be private" rule is a standard for package managers. They should all warn (or error) if the project (or one of its dependencies) is breaking the rule.

In this case I'll open an issue on the npm repo and any other repo breaking the rule and we can close this one.

2. The rule is not standard, only yarn is applying it.

In this case yarn should not warn for dependencies breaking the rule since they may use another package manager.

I agree that it is only a warning and it can be ignored, but some warnings need to be addressed and this one is just creating noise. It is encouraging devs to ignore every warnings, making warnings useless

dylang commented 2 years ago

This warning is typically for the a third party dependency or dependency of a dependency getting installed.

It's not likely useful for developer running the install.

This is made extra confusing by not showing the name of the module the warning is for.

My opinion is that this warning should only be displayed when publishing if a published package has workspaces in the package.json. It should not be shown at install. At this point it's too late and has no effect on the install so it doesn't matter.

The only time it should be shown at install time is if this problem is with one of the packages in the workspace. And if that's the case, it should say which package that is.

kiranojhanp commented 1 year ago

In my case, I was trying yarn add but our monorepo was using pnpm. Silly mistake in my part.

Tofandel commented 1 year ago

The piece of code throwing the warning

https://github.com/yarnpkg/yarn/blob/3119382885ea373d3c13d6a846de743eca8c914b/src/config.js#L873-L876

ijemmao commented 1 year ago

Is there any update on this issue? I'm experiencing this issue in my public repo: https://github.com/nkowaokwu/igbo_api/actions/runs/4455179532/jobs/7824826839?pr=576

AnonymousX86 commented 1 year ago

It is possible to explicitly disable it ^1 in .yarnrc file. ^2

nopeless commented 1 year ago

Is it not possible to inform the developer which project is actually offending? i.e. the workspace project that does not have "private": true? This seems like a useful feature

alfaproject commented 1 year ago

I guess no hope for this?

natesire commented 1 year ago

error Workspaces can only be enabled in private projects.

It's related to the built-in @npmcli dependencies using workspaces. I have been debugging the other side of the issue from the npm side. I had to switch to yarn just to work around things. NPM CLI is broken on windows for Node 16.14+ because of NPM.

Then I saw all of these warnings pop up related to workspaces when running yarn.

https://github.com/npm/cli/pull/6601

markedwards commented 1 year ago

It is possible to explicitly disable it 1 in .yarnrc file. 2

Perhaps stating the obvious, but this doesn't apply if your project uses workspaces. In my case, my project uses workspaces correctly, but some dependency violates the rule, hence the warning. So I'm stuck until this is silenced.

rmclaughlin-nelnet commented 1 year ago

We are in the process of converting from NPM to Yarn, because NPM nohoist options suck, and we ran into this. What is the logic behind restricting workspaces to only private projects?

ckhatton-transreport commented 1 year ago

After 1.5yrs of this ticket being open, this comment above seems the only option 😓 https://github.com/yarnpkg/yarn/issues/8580#issuecomment-1483520779

rally25rs commented 1 year ago

@ckhatton-transreport

After 1.5yrs of this ticket being open, this comment above seems the only option

Yarn classic / v1 has not been in active feature development for a couple years. Major version 4 is close to being released. Classic/v1 only receives critical security fixes and bug fixes that would prevent it from working.

While it is an admittedly confusing message, Seeing a warning does not prevent anyone from continuing to use yarn.


@rmclaughlin-nelnet

What is the logic behind restricting workspaces to only private projects?

I didn't write that feature initially, but I believe the thought behind "workspaces" was that they are a collection of deploy-able npm packages (each package in the workspace would be npm published as a library), but they themselves are not supposed to be published libraries. I suspect the thinking behind the private: true check was that having it a private package would help prevent the workspace root from being npm published as a dependency.


I'm going to mark this issue as closed because

I'd also like to take this moment to encourage folks to upgrade to yarn modern where possible.

avarun42 commented 1 year ago

Since this is just a warning I think it can be ignored; the npm library still does get installed into node_modules

This is useless and unproductive. Of course a warning can be ignored, but if a warning is not providing any actionable information whatsoever (you would agree that a yarn user using npm as a transitive dependency is not making a mistake, correct?) then that warning should not exist. Especially since the warning currently doesn't even state which package it's referring to.

I would consider this a bug in yarn v1.

I'm going to mark this issue as closed because [...] the message is a warning that can be suppressed in .yarnrc

Not actually true. The mentioned .yarnrc config turns off workspaces entirely. This is obviously not a solution that works if you're actually using workspaces. However, in that situation the warning message being thrown is both useless and a red herring. You can be inside a private project with workspaces enabled and end up seeing the message due to a transitive dependency.


Keep in mind this problem doesn't just affect users of yarn once. It affects every single installer of a project that's using yarn, who may wonder why they're seeing a warning only to end up on this thread that's telling them to ignore it — by definition a waste of time and productivity for everybody that could be solved by simply not showing a useless warning.

jonkoops commented 11 months ago

This bug should be re-opened and fixed, it is an issue in Yarn v1, since it is still the default, even when initializing a new project. This is actively causing issues for users of classnames (https://github.com/JedWatson/classnames/pull/329#issuecomment-1871740033).

malininss commented 9 months ago

Why is there no reaction if this is obviously a bug? I use workspaces in my project and can't turn them off in .yarnrc

darklight9811 commented 5 months ago

Also think this still a bug that should be fixed

mjugger commented 4 months ago

this is not even a warning it is throwing an error for me and preventing the project from being installed. is there a way to completely bypass this?

fulldecent commented 3 months ago

Here is the solution to this issue (not a workaround). The issue should stay closed because it is solved.

tl;dr You are running and old version of Yarn. And when you think you are upgrading it you are not.


Root cause

You are running an old version of Yarn. And when you think you are upgrading Yarn, you are not.

Proof:

yarn --version

Compare to actual current Yarn releases.

Things that don't work ❌

Don't do these things. Intuitively they look like they will work but actually they do nothing.

Solution

Uninstall Yarn on your system if you installed it using any non-preferred (even retroactively non-preferred) ways.

brew uninstall yarn

Then install the preferred way. (Here is how I prefer, there are others.)

brew install nvm
nvm install --lts --reinstall-packages-from=current # If you don't use that second flag you get old version
nvm use --lts

Then install yarn

corepack enable # You already have this command installed when you installed Node.js

Then delete your .lock file which may be preventing upgrades

rm yarn.lock

Now you can use yarn

yarn install
yarn set version stable # This will update your package.json to add a $.packageManager entry

Notice how everything looks different? You are on the new version now. And the warning is gone.


Follow on work

Please feel free to ignore any of this. Good vibes only.

Here's how I think the world can be a better place:

markedwards commented 3 months ago

@fulldecent this issue is not about yarn berry, its about yarn v1. Please see the above discussion.

benquarmby commented 3 months ago

:trollface: Yarn Berry, the Node ~package manager~ module system replacement nobody asked for.

Another alternative is switching to pnpm, which just keeps delivering on the original promise of Yarn 1.x; a faster more stable NPM. None of these package managers are perfect. PNPM has its own issues just like yarn 1.x, but it's actively maintained, and this particular warning does not happen. pnpm import ./yarn.lock is a great place to start.

Tofandel commented 3 months ago

It's also not just brew, if v1 really should not be installed then it shouldn't be the default in the distros package managers. Right now apt install yarn on any distro will get you v1 by default. Same with npm npm install --global yarn will get you v1

sudo yarn self-update ? This will do nothing https://classic.yarnpkg.com/lang/en/docs/cli/self-update/

curl --compressed -o- -L https://yarnpkg.com/install.sh | bash will install v1

If they really want people to upgrade to v4 then it shouldn't be so painfully hard to do so

Instead yarn v4 has to be installed on top of v1 for any project that you run, it cannot be installed globally AFAIK

Yarn berry is in a completely different project so the releases are not tracked in this one and that's probably because it's now a completely different package manager

So yeah do yourself a favor and switch back to npm or pnpm which have come a long long way since then compared to yarn