简体   繁体   English

如何保证依赖的依赖会直接安装在“node_modules”下面?

[英]How to guarantee that dependency of dependency will be installed directly below "node_modules"?

The package @yamato-daiwa/style_guides has below depencencies: @yamato-daiwa/style_guides 包有以下依赖项:

{
  "name": "@yamato-daiwa/style_guides",
  "version": "0.0.14",
  // ...
  "dependencies": {
    "@typescript-eslint/eslint-plugin": "5.29.0",
    "@typescript-eslint/parser": "5.29.0",
    "eslint": "8.18.0",
    "eslint-plugin-import": "2.26.0",
    "eslint-plugin-node": "11.1.0",
    "eslint-plugin-vue": "9.1.1",
    "eslint-plugin-vue-pug": "0.5.2"
  }
}

I don't want to make user of @yamato-daiwa/style_guides install these depencies manually - I want "everything out of the box" approach.我不想让@yamato-daiwa/style_guides 的用户手动安装这些依赖项——我想要“开箱即用”的方法。

Depending on project, "@typescript-eslint/eslint-plugin", "@typescript-eslint/parser" and other dependecies are being installed directly below "node_modules" or no:根据项目,“@typescript-eslint/eslint-plugin”、“@typescript-eslint/parser”和其他依赖项直接安装在“node_modules”下方或不安装:

Directly below exmaple正下方示例

在此处输入图像描述

Deep example深度示例

在此处输入图像描述

Currently, the regularity is not clear for me, but if "@typescript-eslint/eslint-plugin" and other dependencies will not be installed directly below node_modules , the ESLint simplty will not work:目前,规律性对我来说还不清楚,但如果"@typescript-eslint/eslint-plugin"和其他依赖项不会直接安装在node_modules下,则 ESLint simplty 将不起作用:

在此处输入图像描述

Although I still don't understand the concept of peerDependencies , I suppose it does not fit for the implementation of "out of box" approach:虽然我仍然不了解peerDependencies的概念,但我认为它不适合“开箱即用”方法的实现:

When a dependency is listed in a package as a peerDependency, it is not automatically installed .当依赖项在包中列为 peerDependency 时,它不会自动安装 Instead, the code that includes the package must include it as its dependency.相反,包含包的代码必须包含它作为其依赖项。

https://flaviocopes.com/npm-peer-dependencies/ https://flaviocopes.com/npm-peer-dependencies/

You might find the checklist mentioned in this answer helpful to debug the issue: How to prevent nested node_modules inside node_modules您可能会发现此答案中提到的清单有助于调试问题: How to prevent nested node_modules inside node_modules

As mentioned, you will get a nested node_modules folder inside your package @yamato-daiwa when the versions of @typescript-eslint/eslint-plugin and @typescript-eslint/parser you are using ( 5.29.0 ) are different from the same modules used in your user's project.如前所述,当您使用的@typescript-eslint/eslint-plugin@typescript-eslint/parser的版本( 5.29.0 )与相同的模块不同时,您将在包@yamato-daiwa中获得一个嵌套的node_modules文件夹在您用户的项目中使用。 You can try deduplicating them using npm-dedupe , and if it works you can add it as a post-install script in your package.您可以尝试使用npm-dedupe 对它们进行重复数据删除,如果可行,您可以将其作为安装后脚本添加到您的包中。

Also, check if the issue is fixed by prefixing the eslint plugin and parser versions with a ^ .另外,通过在 eslint 插件和解析器版本前加上^来检查问题是否已解决。 So, it would be "^5.29.0" ;因此,它将是"^5.29.0" this will allow npm or yarn to automatically fetch the latest version of the dependencies and flatten them to use a single version across the project.这将允许npmyarn自动获取最新版本的依赖项并将它们展平以在整个项目中使用单个版本。

Yes, dependencies are always installed automatically, yes, peerDependencies are only installed manually.是的, dependencies项总是自动安装的,是的, peerDependencies只是手动安装的。

But, the actual issue is that you're opening files under node_modules while those aren't supposed to be opened.但是,实际问题是您正在打开node_modules下的文件,而这些文件不应该打开。

In order to browse a dependency, clone and open their repository as a separate project, then install all dependencies.为了浏览依赖项,克隆并将其存储库作为单独的项目打开,然后安装所有依赖项。

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

相关问题 如何从 node_modules 导入本地依赖项 - How to import local dependency from node_modules 依赖关系 - 未安装错误(npm WARN可选SKIPPING OPTIONAL DEPENDENCY:fsevents@^1.0.0(node_modules \ chokidar \ node_modules \ fsevents) - Dependencies - not installed error (npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents) 从node_modules中的依赖关系中复制文件 - Copy file from node_modules in a dependency 为什么 yarn install 下载 node_modules 依赖? - Why yarn install downloads node_modules for dependency? ./node_modules/express/lib/view.js 中的 Webpack 警告关键依赖:依赖的请求是一个表达式 - Webpack WARNING in ./node_modules/express/lib/view.js Critical dependency: the request of a dependency is an expression 节点模块依赖问题 - Node modules dependency issue 如何仅从package.json创建npm / yarn依赖树; 不创建node_modules文件夹 - How to create npm/yarn dependency tree from just package.json; without creating node_modules folder 如何解决节点模块编译中的循环依赖? - How to resolve circular dependency in compilation of node modules? 如何使用本地安装在 node_modules 中的包中的可执行文件? - How to use executables from a package installed locally in node_modules? 如何计算 macOS 上安装的所有 node_modules 的大小? - How to calculate size of all node_modules installed on macOS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM