当我尝试使用node.js安装sass时,为什么终端中的权限被拒绝

当我尝试使用node.js安装sass时,为什么终端中的权限被拒绝,node.js,npm,sass,Node.js,Npm,Sass,为什么我不能安装?救命啊!我遵循了本教程,它告诉我安装node.js,我确实安装了 karenchan:~ karenchan$ npm install -g sass npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules npm ERR! code EACCES npm ERR! syscall access npm ERR! path /usr/local/lib/node_modules

为什么我不能安装?救命啊!我遵循了本教程,它告诉我安装node.js,我确实安装了

karenchan:~ karenchan$ npm install -g sass
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
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! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/karenchan/.npm/_logs/2020-07-30T20_33_04_760Z-debug.log
karenchan:~ karenchan$ npm install -g sass
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
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! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/karenchan/.npm/_logs/2020-07-30T20_44_30_523Z-debug.log
karenchan:~ karenchan$ 
这就是问题所在:

Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
两种解决方案:

  • 使用“根目录”全局安装

  • 本地安装(因此“权限”不应成为问题):

    cd
    npm安装sass
    
  • 供参考,其他选项可能包括:

    • 编辑项目的

    • 安装和使用

    下面是关于后者的一个很好的教程:


    Duplicate:try'sudo npm install-g sass'我认为您需要提升权限才能进行全局安装(-g)我尝试了您的第二种方法,结果“password”一词出现了一个图标,这是什么意思?我以后什么也打不出来了每天都能用谢谢
    sudo npm install -g sass
    
    cd <<my project>>
    npm install sass