简体   繁体   English

如何正确安装eslint-config-airbnb? `UNMET PEER DEPENDENCY`

[英]How to install eslint-config-airbnb properly ? `UNMET PEER DEPENDENCY`

➜  beslint git:(master) ✗ eslint -v
    v3.15.0
➜  beslint git:(master) ✗ npm install -g eslint-config-airbnb eslint-plugin-jsx-a11y eslint-plugin-import eslint-plugin-react

/Users/next/.nvm/versions/node/v7.5.0/lib
├── UNMET PEER DEPENDENCY eslint@^3.15.0
├─┬ eslint-config-airbnb@14.1.0
│ └── UNMET PEER DEPENDENCY eslint@^3.15.0
├── eslint-plugin-import@2.2.0
├── eslint-plugin-jsx-a11y@4.0.0
└── eslint-plugin-react@6.10.0

npm WARN eslint-config-airbnb@14.1.0 requires a peer of eslint@^3.15.0 but none was installed.
npm WARN eslint-config-airbnb-base@11.1.0 requires a peer of eslint@^3.15.0 but none was installed.
npm WARN eslint-plugin-import@2.2.0 requires a peer of eslint@2.x - 3.x but none was installed.
npm WARN eslint-plugin-jsx-a11y@4.0.0 requires a peer of eslint@^2.10.2 || 3.x but none was installed.
npm WARN eslint-plugin-react@6.10.0 requires a peer of eslint@^2.0.0 || ^3.0.0 but none was installed.
➜  beslint git:(master) ✗
  • I tired to install globally 我厌倦了全球安装
  • I use nvm to install node 7.5.0 , and installed eslint globally. 我使用nvm安装node 7.5.0 ,并在全局安装了eslint。
  • when I try to install eslint-config-airbnb globally. 当我尝试在全球安装eslint-config-airbnb
  • It said UNMET PEER DEPENDENCY 它表示UNMET PEER DEPENDENCY

You can install eslint-config-airbnb-bundle . 您可以安装eslint-config-airbnb-bundle This is an unaltered Airbnb style guide config bundled with ESLint in a single package to solve some inconvenience with the installation (like unmet peer dependency warnings). 这是一个未经改动的 Airbnb风格指南配置与ESLint捆绑在一个软件包中,以解决安装带来的一些不便(如未完成的对等依赖性警告)。 You can install it globally as well: 您也可以在全球范围内安装它:

npm i -g eslint-config-airbnb-bundle

Airbnb only: https://www.npmjs.com/package/eslint-config-airbnb-bundle 仅限Airbnb: https//www.npmjs.com/package/eslint-config-airbnb-bundle

Airbnb + Standard: https://www.npmjs.com/package/eslint-config-airbnb-standard Airbnb +标准: https//www.npmjs.com/package/eslint-config-airbnb-standard

I faced similar issue but found a solution to this issue. 我遇到了类似的问题,但找到了解决这个问题的方法。 I thought its worth sharing. 我认为值得分享。

To install the correct versions of each package related eslint config , You can run following command : 要安装与每个软件包相关的eslint配置的正确版本,您可以运行以下命令:

npm info "eslint-config-airbnb@latest" peerDependencies

You can get exact peer dependency which are listed by running above command: 您可以通过运行以上命令获得列出的精确对等依赖项:

eg about outputs ( as of answer's date ) will produce following : 例如关于输出(截至答复日期)将产生以下内容:

{ eslint: '^3.19.0 || ^4.3.0',
  'eslint-plugin-jsx-a11y': '^5.1.1',
  'eslint-plugin-import': '^2.7.0',
  'eslint-plugin-react': '^7.1.0' 
}

From above output you can exact idea about what dependencies to install for current ( latest build) . 从上面的输出中,您可以准确了解要为当前(最新版本)安装的依赖项。

If you want to install all dependencies in one go ( for Linux/OSX users only) Use below command : 如果要一次安装所有依赖项(仅适用于Linux / OSX用户)请使用以下命令:

(
  export PKG=eslint-config-airbnb;
  npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest"
)

More details here . 更多细节在这里

来自https://www.npmjs.com/package/eslint-config-airbnb

npx install-peerdeps --dev eslint-config-airbnb

删除节点模块( rm -rf node_modules/ )并重新运行npm install对我rm -rf node_modules/ !!

I don't think you should install everything global. 我不认为你应该安装全局的一切。 Try this: 尝试这个:

npm install --save-dev eslint eslint-config-airbnb eslint-plugin-jsx-a11y eslint-plugin-import eslint-plugin-react

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

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