【问题标题】:Why cannot i download nodemon?为什么我不能下载nodemon?
【发布时间】:2022-01-10 08:30:47
【问题描述】:

我正在尝试下载 nodemon,但我很不确定为什么它没有下载。我遇到以下错误?

npm install -g nodemon

npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/nodemon
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/nodemon'
npm ERR!  [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/nodemon'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/usr/local/lib/node_modules/nodemon'
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/ryandevasia/.npm/_logs/2021-12-04T05_47_29_366Z-debug.log

下载模块需要做什么?

【问题讨论】:

    标签: node.js npm nodemon


    【解决方案1】:

    EACCES 错误表示npm 没有安装全局包的权限。为此,您需要使用sudo 以root 身份(具有npm 全局目录的权限)运行该命令。因此,您可以使用管理员帐户运行sudo npm install -g nodemon,输入密码后即可运行。

    【讨论】:

    • 我碰巧有同样的问题,用 npm 下载 sqlite3 会 sudo 工作
    • 它应该适用于全局安装任何东西。但是如果是项目依赖的库,就应该在本地安装。全局内容适用于 CLI 和其他工具(如 nodemon)。
    【解决方案2】:

    尝试使用 sudo 安装:

    sudo npm install -g nodemon
    

    通常最好将nodemon 安装为开发依赖项

    npm i -d nodemon
    

    这样您就可以将其构建到您的脚本中,并且有助于协作:

    "start" : "nodemon index.js"
    

    【讨论】:

    • 如果您在一个 npm 项目中处理多个 js 文件或在一个 npm 项目之外处理多个 js 文件,您可能需要全局安装 nodemon。
    • 我一直发现与多人一起工作的项目尝试复制环境很复杂,因此将其构建为依赖项并添加为脚本效果更好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 2014-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多