npm 工作空间“警告:过滤器集中有某些包名称,但不存在工作空间文件夹”

发布于 2025-01-10 21:51:41 字数 794 浏览 0 评论 0原文

我有一个包含许多 npm 包的存储库,使用 npm 工作区

-level package.json 包含以下行:

  "workspaces": [
    "*"
  ]

当我运行 npm i -ws 或其他 npm 命令时,我收到警告:

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

我不太确定该消息的含义- 我认为“过滤器集”是-w选项,但工作区文件夹some-package-name确实存在。

需要注意的是,some-package-name/package.json 包含一个 org 前缀,例如:

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

所以也许这就是原因。我无法将文件夹从 some-package-name 重命名为 @mycompany/some-package-name 但因为我担心以 @ 开头的目录 可能会破坏东西。

该警告是什么意思以及如何解决它?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

情定在深秋 2025-01-17 21:51:41

我遇到了同样的问题,使用工作区包中配置的名称而不是文件夹名称为我解决了问题,即使使用 @ 也是如此。

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

相关软件包 package.jsonpackage-lock.json< 可能会出现此问题/code> name 字段与工作区文件夹命名和包名称和/或彼此不匹配。

该命令更新了两个 name 字段,以便警告消失。

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.

岁月打碎记忆 2025-01-17 21:51:41

我最近在 monorepo 中遇到了同样的问题:原因是 package.json 中的项目名称(不带范围)与其存储的目录(子项目)名称不匹配。

如果 monorepo 的子项目存储在项目根目录中的 packages 目录中,并且根 package.json 包含,

"workspaces": [
    "packages/*"
]

npm 需要一个名为@/project-name 位于目录 packages/project-name 中。

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.

原谅过去的我 2025-01-17 21:51:41

我的答案略有不同。

我正在使用 Fs.writeFileSync('./path/to/package.json') 以编程方式创建 package.json

我随后立即运行 npm install -w=workspace foo bar ,但似乎有时会失败; NPM 不知何故没有获取该文件,就好像我运行同一命令两次一样,第二个命令总是有效。

使用 setTimeout() 添加一个小的延迟也可以,尽管我觉得不得不这样做有点肮脏;我不知道这是 Node 的问题还是我对 Node 进程生命周期缺乏了解。

不管怎样,在这种情况下——而不是更好的解决方案——它是有效的。

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.

笨死的猪 2025-01-17 21:51:41

我使用 file: 依赖项作为“npm 推荐”解决了这个问题(请参阅下文)。

实际上,很多文章都说 npm 建议使用 file: 来引用两个工作区包之间的依赖关系(然后它们通常使用星号),但老实说,我没有在 npm 文档中找到该提示,但它作品! ...至少它对我有用,使用以下

内容显式列出工作空间

因此,我没有使用星号,例如

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

我还有一个作用域包名称

,例如

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

我使用“文件:”依赖项

而不是

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

使用<代码>文件:WORKSPACE_PATH

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

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"
  }
离旧人 2025-01-17 21:51:41

对我来说,当我使用turborepo使用monorepo(使用命令-npx create-turbo@latest创建)时,我收到了这个警告/问题。

我收到错误是因为我更改了 nextjs 项目的名称。但我没有更改 package.json 中的 name 属性。 当 name 属性更改为文件夹/包的名称时,问题得到解决。

更改 package.json 中的 name 属性后,请确保重新安装 tailwind 或您正在安装的任何其他软件包。就不会提示上面的错误了。

参考下图:package/project 的名称是 user-app 但在 package.json 中名称是 web,我将此名称编辑为user-app,问题得到解决。

输入图片此处描述

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文