[英]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.这将允许
npm
或yarn
自动获取最新版本的依赖项并将它们展平以在整个项目中使用单个版本。
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.