简体   繁体   English

子package.json中的root package.json未满足依赖项

[英]Root package.json unmet dependency in child package.json

Lets say I have a Typescript project like so 可以说我有一个像这样的Typescript项目

root/
  api/
    package.json
  web/
    package.json
  ...
  package.json

In the root package.json I have the typescript dependency installed (this is to ensure it uses the same version in web & api). 在根package.json我安装了打字稿依赖项(以确保它在Web和api中使用相同的版本)。

If I install a package in web/package.json that has a peerDepedency on Typescript (lets say ts-loader ) it will complain that Typescript is an unmet dependency. 如果我在web / package.json中安装了一个在peerDepedency上具有peerDepedency的软件包(让我们说ts-loader ),它将抱怨Typescript是未满足的依赖项。

root package.json 根package.json

{
  ...
  "devDependencies": {
    "@types/node": "^11.11.7",
    ...
    "typescript": "^3.3.4000"
  }
}

web/package.json 网络/的package.json

{
  ...
  "devDependencies": {
    "ts-loader": "^5.3.3",
    "webpack": "^4.29.6"
  }
}

How do I get around this without adding Typescript in the web/package.json ? 如何解决此问题而不在Web / package.json中添加Typescript?

If thats not possible, how do you ensure that the same version of packages is used across multiple modules? 如果那不可能,那么如何确保在多个模块中使用相同版本的软件包?

Unfortunately npm doesn't have any sort of package.json inheritance. 不幸的是,npm没有任何package.json继承。

Since it's just a warning & everything should still work since node looks for node_modules in parent directories, I think you can do one of these: 由于这只是一个警告,并且由于节点在父目录中查找node_modules ,因此一切仍然应该工作,我认为您可以执行以下操作之一:

  • Just ignore the warning 只是忽略警告
  • Move ts-loader up to parent directory ts-loader移至上级目录
  • Declare & install an exact version of typescript in each sub directory ( without any modifier ) and update them manually whenever necessary 在每个子目录中声明并安装确切版本的打字稿( 不带任何修饰符 ),并在必要时手动进行更新
  • Switch to yarn & use workspaces (I think you'd still have to list typescript in each package's dependencies, but at least they will be installed only once.) 切换到yarn&use 工作区 (我认为您仍然必须在每个包的依赖项中列出打字稿,但至少它们只会安装一次。)
  • Use lerna , a js monorepo manager that can manage cross dependencies 使用lerna ,这是一个可以管理交叉依赖项的js monorepo管理器

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

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