代码之家  ›  专栏  ›  技术社区  ›  stack12321

无法在MacOS上安装Typescript-终端错误

  •  0
  • stack12321  · 技术社区  · 6 年前

    我的mac上有visual studio代码,想安装angular的typescript。我之前已经安装了node.js或git。如果typescript在mac终端上运行,那么来自typescript网站的这个命令应该安装typescript,但是它没有:

    npm install -g typescript
    

    如果我将其粘贴到终端中并按回车键,则此错误代码将显示在终端中:(有什么问题?我真的不明白,也不知道终端,我不是电脑专家。如果你能给初学者一些简单易懂的建议,那将是一个很大的帮助。谢谢!!)

    MacBook-Pro:~ Max$ npm install -g typescript
    npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
    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!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
    npm ERR!   stack:
    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! 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 (though this is not recommended).
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     /Users/Max/.npm/_logs/2018-06-30T14_50_35_633Z-debug.log
    MacBook-Pro:~ Max$ clear
    
        MacBook-Pro:~ Max$ npm install -g typescript
        npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
        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!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
        npm ERR!   stack:
        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! 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 (though this is not recommended).
    
        npm ERR! A complete log of this run can be found in:
        npm ERR!     /Users/Max/.npm/_logs/2018-06-30T14_58_29_869Z-debug.log
        MacBook-Pro:~ Max$ clear
    
        MacBook-Pro:~ Max$ npm install -g typescript
        npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
        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!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
        npm ERR!   stack:
        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! 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 (though this is not recommended).
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Joe Warner    6 年前

    npm warn checkpermissions缺少对/usr/local/lib/node_模块的写访问

    意味着您需要权限才能下载到该位置,之所以需要根权限,很可能是因为您安装了具有根权限的nodejs/npm。

    sudo npm install -g typescript

    然后输入密码