从命令行安装ESlint错误

wqu*_*wqu 8 javascript terminal node.js eslint

我在安装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
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚如何安装eslint并获得这一行:

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

Nel*_*elu 10

如果你正在eslint: command not found尝试:

./node_modules/.bin/eslint --init
Run Code Online (Sandbox Code Playgroud)


小智 7

当您的用户无权访问全局node_modules文件夹时,您似乎正在尝试全局安装.您可以尝试以root用户身份安装它,也可以选择"/ usr/local/lib/node_modules".

以root身份安装 -

    sudo npm install -g eslint
Run Code Online (Sandbox Code Playgroud)

Chown -

    chown user:group /usr/local/lib/node_modules
    npm install -g eslint
Run Code Online (Sandbox Code Playgroud)

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

编辑:尝试在OSX上全局安装ESlint时,请在此处的答案"权限被拒绝"中尝试解决方案

将其添加到〜/ .npmrc:

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


Raj*_*kar 6

尝试

npm install eslint --save-dev进而eslint --init

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

  • 你必须从项目文件夹 /node_modules/.bin/eslint --init 运行它。与其他方法相比,这是安全的。 (6认同)