理解NPM依赖性



我正在尝试确切地弄清NPM依赖项的情况。

我问题的最短形式是:鉴于我的传递依赖图多次调用特定包装,为什么这些不同的版本在npm list或文件系统中未显示?

我不想将垃圾的全局名称空间弄乱,因此可以使用我的实际当前项目;我认为这足够小,可以清楚。

C:ayane>npm list
ayane@3.0.1 C:ayane
+-- clause-normal-form@2.4.0
| +-- big-integer@1.6.22
| +-- big-rational@0.10.6
| +-- clone@2.1.1
| `-- lodash@4.17.4
+-- command-files@1.1.0
| `-- glob@7.1.1
|   +-- fs.realpath@1.0.0
|   +-- inflight@1.0.6
|   | `-- wrappy@1.0.2
|   +-- inherits@2.0.3
|   +-- minimatch@3.0.3
|   | `-- brace-expansion@1.1.7
|   |   +-- balanced-match@0.4.2
|   |   `-- concat-map@0.0.1
|   +-- once@1.4.0
|   `-- path-is-absolute@1.0.1
+-- commander@2.9.0
| `-- graceful-readlink@1.0.1
+-- dimacs-parser@2.3.0
+-- get-stdin@5.0.1
+-- iop@1.4.1
`-- tptp-parser@2.5.1

到目前为止看起来不错的

除了ayane取决于clause-normal-form 2.4.0,但是dimacs-parsertptp-parser取决于clause-normal-form 2.3.0;为什么这不显示上述?

C:ayane>tree /a
Folder PATH listing for volume OS
Volume serial number is C685-B1F1
C:.
---node_modules
    +---.bin
    +---balanced-match
    +---big-integer
    +---big-rational
    +---brace-expansion
    +---clause-normal-form
    +---clone
    +---command-files
    +---commander
    +---concat-map
    |   +---example
    |   ---test
    +---dimacs-parser
    +---fs.realpath
    +---get-stdin
    +---glob
    +---graceful-readlink
    +---inflight
    +---inherits
    +---iop
    +---lodash
    |   ---fp
    +---minimatch
    +---once
    +---path-is-absolute
    +---tptp-parser
    ---wrappy

同样的问题:为什么只出现一个clause-normal-form目录?

这可能是因为它只会安装同一模块的一个版本,除非另有说明。如果clause-normal-form版本2.3.0和2.4.0不兼容,这将是一个问题,如果它们有的话,您可能会遇到一些麻烦。对于最佳解决方案,因此您的代码无需问题就可以使用package.json

中的peerDependencies

https://nodejs.org/en/blog/npm/peer-depperencies/

P.S:这在NPM版本3及更高版本上不起作用,只会给我们手动安装它们

警告

最新更新