[英]How to deal with NPM error: Cannot set properties of null (setting 'parent')?
This NPM error happens when used in a monorepo with NPM workspaces feature.当在具有 NPM 工作区功能的 monorepo 中使用时,会发生此 NPM 错误。 I have a monorepo with 5 packages: a
, b
, c
, d
and e
.我有一个包含 5 个包的 monorepo: a
、 b
、 c
、 d
和e
。 I also have a package in a different repository which is not a workspace.我在另一个不是工作区的存储库中也有一个 package。 The name of that package is x
and it depends on package c
and d
. package 的名称是x
,它取决于 package c
和d
。
The problem happens when I try to add package x
as a dependency for my package e
.当我尝试将 package x
添加为我的 package e
的依赖项时,就会出现问题。 Every time I try: npm install x -w packages/e
, I get following error:每次我尝试: npm install x -w packages/e
,我都会收到以下错误:
npm ERR! Cannot set properties of null (setting 'parent')
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/harshal/.npm/_logs/2022-11-11T17_27_57_008Z-debug-0.log
There is absolutely nothing in the error log except the fact that the error originates in arborist
package when resolving dependencies.错误日志中绝对没有任何内容,除了错误起源于arborist
package 在解析依赖项时。
I have tried using multiple NPM versions ^8.xx
but it doesn't seem to resolve it.我试过使用多个 NPM 版本^8.xx
但它似乎没有解决它。
The issue is the circular dependency - monorepo depends on external package that depends back on the monorepo.问题是循环依赖——monorepo 依赖于外部 package,而后者又依赖于 monorepo。 When trying to resolve it seems to set the monorepo packages as 'null' (so as to defer resolution w/o hanging) and then when it tries to resolve that package it just fails.尝试解决时,它似乎将 monorepo 包设置为“空”(以便推迟解决而不挂起),然后当它尝试解决 package 时,它就失败了。 I don't have a workaround, trying to figure that out for myself.我没有解决方法,试图自己解决这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.