简体   繁体   English

如何获得NPM模块以正确安装其依赖项?

[英]How do I get my NPM module to install its dependencies correctly?

I'm having problems with my home-rolled NPM module as when installed it installs most of it's dependencies in the applications node_modules directory, instead of containing it inside the module itself. 我的家用NPM模块在安装时遇到问题,因为它在安装时会将大多数依赖项安装在应用程序的node_modules目录中,而不是将其包含在模块本身中。

Ex; 防爆;

APP
    node_modules
        MY_MODULE
            node_modules
                <ALL deps from MY_MODULE should be installed here>
        <SOME/MOST deps from MY_MODULE are installed here>

The above causes issues because I have dependencies that require a specific version that's installed under MY_MODULE/node_modules and NOT under MY_APP/node_modules. 上面的原因引起了问题,因为我的依赖项需要安装在MY_MODULE / node_modules下而不是MY_APP / node_modules下的特定版本。

For instance; 例如; I have Webpack 3 installed under APP/node_modules but MY_MODULE requires Webpack 4 and that is installed under MY_MODULE/node_modules as you would expect. 我已经将Webpack 3安装在APP / node_modules下,但是MY_MODULE需要Webpack 4,并且正如您所期望的那样,它已安装在MY_MODULE / node_modules下。 But everything else, that requires Webpack 4, is installed under APP/node_modules and thus gives an error message. 但是需要Webpack 4的其他所有内容都安装在APP / node_modules下,因此会显示错误消息。

So, in the app I have a package.json: devDependencies: "webpack": "^3.12.0", 因此,在应用程序中,我有一个package.json:devDependencies:“ webpack”:“ ^ 3.12.0”,

And in my NPM module I have a package.json: "dependecies": [ "webpack": "^4.12.0", "webpack-cli": "^3.0.8", ] 在我的NPM模块中,我有一个package.json:“ dependecies”:[“ webpack”:“ ^ 4.12.0”,“ webpack-cli”:“ ^ 3.0.8”,]

webpack-cli is installed under APP/node_modules and thus complains that it requires Webpack 4 and that it couldn't be found. webpack-cli已安装在APP / node_modules下,因此抱怨它需要Webpack 4,但找不到。

if webpack-cli instead installed itself under APP / node_modules / MY_MODULE / node_modules it would work. 如果webpack-cli改为将自身安装在APP / node_modules / MY_MODULE / node_modules下,则它将起作用。

How can I get it to do that? 我怎样才能做到这一点?

Thanks, 谢谢,

/J / J

<ALL deps from MY_MODULE should be installed here>

They shouldn't. 他们不应该。 This was true for NPM v2. NPM v2确实如此。 This behaviour had been changed in NPM v3, and now it's v6. 此行为已在NPM v3中更改,现在是v6。

In case dependencies have dependencies with different version constraints that can be satisfied with single webpack (which is one of the reasons why node_modules was flattened in NPM v3), there will be: 如果依赖项具有可以通过单个webpack满足的具有不同版本约束的依赖webpack (这是在NPM v3 node_modules平的原因之一),将有:

node_modules/webpack

Otherwise there will be multiple dependencies that will be used by packages that depend on them: 否则,依赖于它们的软件包将使用多个依赖项:

node_modules/webpack@3.12.0
node_modules/webpack@4.12.0

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

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