从命令行安装ESlint错误

ESlint Error Install from Command Line

我在安装 eslint 时遇到以下错误:

npm ERR! Darwin 15.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "eslint"
npm ERR! node v5.5.0
npm ERR! npm  v3.8.8
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access

npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/Leviathan/lj/npm-debug.log

我还没弄清楚如何安装 eslint 以及如何得到这一行:

eslint --init 到 运行 创建 .eslintrc 文件

尝试

npm install eslint --save-dev 然后 eslint --init.

如果您遇到任何问题,请告诉我。

您的用户无权访问全局 node_modules 文件夹,但您似乎在尝试进行全局安装。您可以尝试将其安装为 root 或 chown '/usr/local/lib/node_modules'.

以 root 身份安装 -

    sudo npm install -g eslint

乔恩 -

    chown user:group /usr/local/lib/node_modules
    npm install -g eslint

您还可以将权限更改为 /usr/local/lib/node_modules 以允许您的用户使用 chmod 进行访问。

编辑: 在此处尝试答案中的解决方案

将此添加到 ~/.npmrc:

prefix = ${HOME}/.npm-packages https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md 您还必须将 ${HOME}/.npm-packages/.bin 添加到您的 PATH,以便您的 shell 知道在哪里查找全局安装的脚本。

我也有 eslint-bash permission denied, command not found。对我来说,解决方案是:
1.找到eslint的安装路径,我的是:
# npm install -g eslint /root/mynode/node-v10.9.0-linux-x64/bin/eslint -> /root/mynode/node-v10.9.0-linux-x64/lib/node_modules/eslint/bin/eslint.js + eslint@5.6.0 updated 1 package in 5.114s 路径是/root/mynode/node-v10.9.0-linux-x64/lib/node_modules/eslint/bin/eslint.js
2.run/root/mynode/node-v10.9.0-linux-x64/lib/node_modules/eslint/bin/eslint.js --init
成功!

eslint --init to run to create the .eslintrc file 是说创建 .eslintrc,你可能忘记在 eslintrc

之前包含 .

如果你得到 eslint: command not found 试试:

./node_modules/.bin/eslint --init

可能正在将 package.json 文件中的依赖项更新到最新版本(包括主要版本更改)。会节省你的时间。

npx npm-check-updates -u

或者您可能必须全局安装 eslint。

npm i eslint -g

并在删除当前项目的节点模块后

eslint --init

对于:Zsh: command not found: eslint

npm install eslint-plugin-react-hooks --save --dev

然后 运行:

npm install -g eslint

它应该有效