2017-05-06 103 views
2

我想弄清楚npm依赖关系到底发生了什么。npm依赖关系的意义

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

我不想用垃圾混淆全局名称空间只是为了测试,所以会使用我当前的实际项目;我觉得它足够小,可以清晰。

C:\ayane>npm list 
[email protected] C:\ayane 
+-- [email protected] 
| +-- [email protected] 
| +-- [email protected] 
| +-- [email protected] 
| `-- [email protected] 
+-- [email protected] 
| `-- [email protected] 
| +-- [email protected] 
| +-- [email protected] 
| | `-- [email protected] 
| +-- [email protected] 
| +-- [email protected] 
| | `-- [email protected] 
| | +-- [email protected] 
| | `-- [email protected] 
| +-- [email protected] 
| `-- [email protected] 
+-- [email protected] 
| `-- [email protected] 
+-- [email protected] 
+-- [email protected] 
+-- [email protected] 
`-- [email protected] 

这看起来到目前为止,除了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目录出现?

回答

1

这可能是因为它只会安装相同模块的一个版本,除非另有说明。如果clause-normal-form版本2.3.0和2.4.0不兼容,那么这将是一个问题,如果它们可能会遇到一些麻烦。为了获得最佳的解决方案,使你的代码工作没有问题,你需要在package.json

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

PS使用peerDependencies:这不会对NPM版本工作3及以上的,它只会给予警告为我们安装他们手动

+0

你是对的!如果它们在主要版本上有所不同,它可以处理两者。 – rwallace