简体   繁体   English

自定义节点模块的依赖项未安装在根目录上

[英]custom node module's dependency not installed on root

I have a app project and 2 node module projects.我有一个应用程序项目和 2 个节点模块项目。

The dependencies structure is something like this:依赖结构是这样的:

App {
  NodeModule1 {
    NodeModule2,
    ...
  },
  ...
}

The problem I have is that my NodeModule2 instead of being installed on the root of app's node_module App/node_modules/NodeModule2 , it is installed in App/node_modules/NodeModule1/node_modules/NodeModule2我遇到的问题是我的 NodeModule2 不是安装在应用程序的 node_module App/node_modules/NodeModule2的根目录上,而是安装在App/node_modules/NodeModule1/node_modules/NodeModule2

This is causing some error on runtime, says my NodeModule2 is not found.这会导致运行时出现一些错误,说我的 NodeModule2 没有找到。 My workaround is to add NodeModule2 into App directly, which is not an idea solution.我的解决方法是直接将 NodeModule2 添加到 App 中,这不是一个理想的解决方案。

All other dependencies of NodeModule1 are installed at App/node_modules/.. as expected. NodeModule1 的所有其他依赖项都按预期安装在 App/node_modules/.. 中。

My NodeModule2's package.json我的 NodeModule2 的 package.json

{
  "name": "NodeModule2",
  "version": "0.0.2-20210202.1.0",
  "private": false,
  "description": "",
  "author": "",
  "license": "ISC",
  "peerDependencies": {
    "react": "16.13.1",
    "react-native": "0.59.10",
    ...
  }
}

I HAVE GOT IT我明白了

In order for sub node_module to be appeared on the root level, all its peerDependencies s' versions must be matched with App's.为了让子 node_module 出现在根级别,它的所有peerDependencies的版本必须与 App 的版本匹配。

In my case both of my App and NodeModule1 has dependency of react-native-picker-select but with different versions.在我的情况下,我的 App 和 NodeModule1 都dependencyreact-native-picker-select但具有不同的版本。

App {
  dependency: {
    "react-native-picker-select": "^8.0.0"
  }
}

NodeModule1 {
  dependency: {
    "react-native-picker-select": "8.0.0"
  }
}

NodeModule2 {
  peerDependency: {
    "react-native-picker-select": "8.0.0"
  }
}

In this case, App received 8.0.4 and NodeModule1 received 8.0.0.在这种情况下,App 收到 8.0.4,NodeModule1 收到 8.0.0。 Yarn puts NodeModule2 under NodeModule1 and to shared the same dependency version 8.0.0. Yarn 将NodeModule2放在NodeModule1下并共享相同的依赖版本 8.0.0。

Fix: Make sure all versions are matched in App, NodeModule1, and NodeModule2.修复:确保 App、NodeModule1 和 NodeModule2 中的所有版本都匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM