25

I have a repo with many npm packages inside, using npm workspaces

The top-level package.json contains the line:

  "workspaces": [
    "*"
  ]

When I run npm i -ws or other npm commands, I receive the warning:

WARN: some-package-name in filter set, but no workspace folder present

I'm not quite sure what the message means - I think the 'filter set' is the -w option, but the workspace folder some-package-name definitely exists.

One note is that the some-package-name/package.json contains an org prefix, eg:

"name": "@mycompany/some-package-name",

So maybe that's the cause. I can't rename the folder from some-package-name to @mycompany/some-package-name though as I'm concerned a directory starting with @ may break things.

What does the warning mean and how can I resolve it?

1
  • running the command twice worked for me somehow Commented Dec 2, 2022 at 13:29

6 Answers 6

8

I ran into the same problem, using the name configured in the workspace's package instead of the folder name fixed the issue for me, even with an @.

npm install --workspace=@mycompany/some-package-name

The issue may appear for the package in question package.json and package-lock.json name fields do not match the workspace folder naming and package name and / or each other.

The command updated both name fields so that the warning is gone.

Sign up to request clarification or add additional context in comments.

1 Comment

I think that was the cause of my problem too. Essentially - and what I didn't understand - was that -ws stands for all workspaces. -w means a single workspace.
7

I have run into the same problem recently with my monorepo: the reason was that the project's name (without the scope) in package.json did not match the name of the directory (subproject) it was stored within.

If the subprojects of the monorepo are stored within a packages directory in the project root and the root package.json contains

"workspaces": [
    "packages/*"
]

then npm expects a subproject named @<scope>/project-name to be in the directory packages/project-name.

1 Comment

I seem to be getting the same error regardless of whether I make an @scope/module_name directory or just a module_name directory Edit: Turns out if you were faking workspaces by putting a 'node_modules' directory in the path, npm workspaces does not like it, and you have to remove that
3

For me, the issue seemed to be that I had "private": true in my workspace root package json & some of the individual workspace package JSONs. After removing it, the issue seemed to go away. I'm not entirely sure why this is the case it seems unintuitive to me, but there's probably a good reason for it.

Comments

1

I have a slightly different answer.

I'm creating a package.json programatically, using Fs.writeFileSync('./path/to/package.json').

I run npm install -w=workspace foo bar immediately after, but it seems that this fails sometimes; NPM somehow hasn't picked up on the file, as if I run the same command twice, the second one always works.

Adding a small delay using setTimeout() also works, though I feel a bit dirty having had to do this; I don't know if this is an issue with Node or my lack of knowledge around Node's process lifecycle.

Anyway, in this case – and in lieu of better solution – it works.

1 Comment

fs.writeFileSync() should block until complete. However some operating systems acknowledge writes before they've actually happened.
1

For me I was getting this warning/issue when I was using monorepo using turborepo, created using command - npx create-turbo@latest.

I was getting the error because I changed the name of the nextjs project. But I didn't change the name property in package.json. When name property was changed to name of the folder/package, issue was resolved.

Once you change the name property in package.json, make sure you re-install the tailwind or any other packages you were installing. It will not prompt the above error.

Refer to the below image: the name of the package/project is user-app but in the package.json name is web, I edited this name to user-app and the issue was resolved.

enter image description here

1 Comment

Have an upvote. But please include the text instead of images, that way your answer will appear when people search.
0

I solved this issue using a file: dependency as "recommended by npm" (read below).

Actually many articles say that npm recommends to use file: to reference a dependency between two workspace packages (and then often they use the asterisk anyway) but honestly I did not found that hint in npm docs, but it works! ... at least it worked for me, using the following

Explicitly list the workspaces

So instead of using an asterisk I have, for example

  "workspaces": [
    "packages/models",
    "packages/database",
    "webapp"
  ]

I also have a scoped package name

for instance

  "name": "@project/models",
  "private": "true"

I am using "file:" dependencies

Instead of

  "dependencies": {
    "@project/models": "*"
  }

I use file:WORKSPACE_PATH

  "dependencies": {
    "@project/models": "file:packages/models"
  }

5 Comments

You say "as recommended by npm"; do you have a link to any documentation?
@DaveStewart it is quoted and immediately below I wrote that I found no reference to that in official npm docs but I found few articles googling that mentioned it, that is why I am sharing what I found out. I hope that my message is more clear now.
OK, I just got this working, but I had to use a relative path from the workspace package file: "@tools/web-tools": "file:../../tools/web-tools"... and – of course – run npm install from the root again.
I believe using 'file:' is a legacy way to do monorepo.
Indeed. Each workspaces should have a symlink in the root node_modules that the other workspaces can use to declare proper dependencies, so that you don't have to use file dependencies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.