工作区仍在起吊的nohoist

时间:2019-06-19 21:09:00

标签: yarnpkg monorepo yarn-workspaces

在我的Monorepo内部,我有一个软件包,我想要其中的node_modules中的所有依赖项。

但是无论我做什么,它的node_modules仍然为空。

因此,出于我的问题,我能够通过以下设置重现该问题

/
 package.json
 lerna.json
 node_modules
 packages/
          A/
            node_modules
            package.json
            index.ts
          B/
            node_modules
            package.json
            index.ts

我为此创建了一个repo

Main package.json

{
  "name": "A-B-test",
  "private": true,
  "workspaces": {
    "packages": ["packages/*"],
    "nohoist": [ "**/B" ]
  },
  ...
  "devDependencies": {
    "lerna": "^3.13.4"
  }
}

B/package.json看起来

{
  "name": "@scaljeri/B",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "angular": "^1.7.8"
  },
  "devDependencies": {
    "browserify": "^16.2.3",
    "typescript": "^3.5.2"
  }
}

现在,当我在项目的根目录中运行yarn时,所有依赖项都将安装在根目录node_modules中。

纱线版本​​:1.16.0 节点:12.4.0

任何建议可能是什么问题?

4 个答案:

答案 0 :(得分:3)

将nohoist应用于子程序包的package.json对我有用。

  "workspaces": {
    "nohoist": [
      "*react-native*",
      "*react-native*/**"
    ]
  },

答案 1 :(得分:1)

根据我的经验,有必要以以下方式双重指定每个软件包:

{
  "nohoist": [
    "**/B",
    "**/B/**,
    "**/C",
    ***/C/**
  ]
}

此外,我发现有必要在修改node_modules设置后删除所有现有的nohoist文件夹。因此,如果您的项目位于packages中,并且位于项目目录中,则可以删除所有这些node_modules文件夹,如下所示:

# delete node_modules on linux
rm -rf ./packages/*/node_modules
rm -rf ./node_modules

# install again
yarn install --check-files

答案 2 :(得分:1)

如果您想从提升中排除包 B 节点模块,您可以在 package.json 中执行此操作:

  "workspaces": {
    "nohoist": [
      "**/B",
      "**/B/**"
    ]
  },

之后删除 node_modulesyarn.lock 并再次运行 yarn install 现在你应该看到包/B/node_modules 没有被提升到顶层项目

答案 3 :(得分:1)

我尝试了几个选项,但最终对我有用的唯一一个是在子包中指定 nohoist 选项。无需在根级别指定任何内容。
所以我在 package.json 包中的 B 是:

{
...

  "workspaces": {
    "nohoist": ["**"]
  },

...
}
相关问题