我试图在phpstorm上设置较少,这样我就可以在保存时将.less文件编译为.css。我已经安装了node.js,下一步(根据这个https://www.jetbrains.com/webstorm/help/transpiling-sass-less-and-scss-to-css.html)是在终端上运行这个命令

npm install -g less

然而,当我这样做时,我得到这些错误

☁  ~  npm install -g less
npm WARN install Couldn't install optional dependency: EACCES: permission denied, mkdir '/Users/brentscholl/.npm/mkdirp/0.5.1'
npm WARN install Couldn't install optional dependency: EACCES: permission denied, mkdir '/Users/brentscholl/.npm/graceful-fs/3.0.8'
npm WARN install Couldn't install optional dependency: EACCES: permission denied, mkdir '/Users/brentscholl/.npm/extend/3.0.0'
npm WARN install Couldn't install optional dependency: EACCES: permission denied, mkdir '/Users/brentscholl/.npm/readable-stream/2.0.4'
npm WARN install Couldn't install optional dependency: EACCES: permission denied, mkdir '/Users/brentscholl/.npm/chalk/1.1.1'
npm WARN install Couldn't install optional dependency: EACCES: permission denied, mkdir '/Users/brentscholl/.npm/xtend/4.0.1'
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
/usr/local/lib
└─┬ less@2.5.3
  ├─┬ errno@0.1.4
  │ └── prr@0.0.0
  ├── image-size@0.3.5
  ├── mime@1.3.4
  ├─┬ promise@6.1.0
  │ └── asap@1.0.0
  └─┬ source-map@0.4.4
    └── amdefine@1.0.0

npm ERR! Darwin 15.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "less"
npm ERR! node v5.0.0
npm ERR! npm  v3.3.6
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/brentscholl/npm-debug.log

我在这里完全是个新手,不知道下一步该做什么。任何帮助都将非常感激!


当前回答

在终端窗口中运行这些命令(注意:不要替换$USER部分…这是一个Linux命令来获取你的用户!)

sudo chown -R $USER ~/.npm
sudo chown -R $USER /usr/lib/node_modules
sudo chown -R $USER /usr/local/lib/node_modules

其他回答

在终端窗口中运行这些命令(注意:不要替换$USER部分…这是一个Linux命令来获取你的用户!)

sudo chown -R $USER ~/.npm
sudo chown -R $USER /usr/lib/node_modules
sudo chown -R $USER /usr/local/lib/node_modules

在linux中确保获得所有权限:

sudo su

sudo chown -R $USER /usr/local/lib/node_modules . sh 这个命令可以工作

另一种选择是下载并使用安装程序安装一个新版本。

https://nodejs.org/en/download/

Mac OS X答案

您没有对node_modules目录的写访问权

npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules

将您的User添加到具有写访问权限的目录

打开包含node_modules的文件夹 打开/usr/local/lib/ 在node_modules文件夹上执行cmd+I命令打开权限对话框 在共享和权限部分中添加具有读写访问权限的用户