npm安装依赖错误

npm ERR! code 128
npm ERR! git dep preparation failed
npm ERR! command C:\Program Files\nodejs\node.exe C:\Users\Administrator\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js install --force --cache=C:\Users\Administrator\AppData\Local\n
pm-cache --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-ru
n
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm ERR! code 128
npm ERR! npm ERR! An unknown git error occurred
npm ERR! npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/adobe-webplatform/eve.git
npm ERR! npm ERR! git@github.com: Permission denied (publickey).
npm ERR! npm ERR! fatal: Could not read from remote repository.
npm ERR! npm ERR!
npm ERR! npm ERR! Please make sure you have the correct access rights
npm ERR! npm ERR! and the repository exists.
npm ERR!
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     C:\Users\Administrator\AppData\Local\npm-cache\_logs\2021-09-02T01_57_04_188Z-debug.log

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Local\npm-cache\_logs\2021-09-02T01_59_44_422Z-debug.log

重新npm install

npm ERR! code 1
npm ERR! path E:\NingXiaEducationPMS\src\client\epms-web\node_modules\node-sass
npm ERR! command failed

国内淘宝镜像
npm i -g cnpm --registry=https://registry.npm.taobao.org
cnpm install node-sass

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Lenovo\AppData\Roaming\npm-cache_logs\2020-02-18T05_24_41_971Z-debug.log

运行cmd命令:
npm install npm -g
查看npm版本:
npm -v
项目内:npm install

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: smarteasy@3.8.0
npm ERR! Found: webpack@5.74.0
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"^5.0.0" from less-loader@10.2.0
npm ERR!   node_modules/less-loader
npm ERR!     less-loader@"^10.2.0" from the root project
npm ERR!   peer webpack@"^4.36.0 || ^5.0.0" from sass-loader@10.1.1
npm ERR!   node_modules/sass-loader
npm ERR!     dev sass-loader@"10.1.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! dev script-ext-html-webpack-plugin@"2.1.5" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: webpack@4.46.0
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"^1.0.0 || ^2.0.0 || ^3.0.0 || ^4.0.0" from script-ext-html-webpack-plugin@2.1.5
npm ERR!   node_modules/script-ext-html-webpack-plugin
npm ERR!     dev script-ext-html-webpack-plugin@"2.1.5" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\Administrator\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Local\npm-cache\_logs\2022-08-11T06_48_56_889Z-debug-0.log

npm install --legacy-peer-deps

### 如何通过 `npm install` 安装项目依赖 当使用 `npm install` 命令时,它会读取项目的 `package.json` 文件中的依赖列表,并自动下载和安装所需的包到当前项目的 `node_modules` 目录下。以下是关于该命令的一些重要细节: #### 1. **基本用法** 执行以下命令即可安装 `package.json` 中定义的所有依赖项: ```bash npm install ``` 此命令会在本地创建或更新 `node_modules` 目录,并将所有声明的生产环境依赖安装进去[^4]。 --- #### 2. **全局安装 vs 局部安装** - 如果希望某个工具可以在系统的任何地方被调用,则可以使用 `-g` 参数进行全局安装。例如: ```bash npm install -g eslint ``` - 默认情况下,不带参数的 `npm install` 只会影响当前项目所在的局部范围。 --- #### 3. **指定特定依赖项** 如果需要手动添加一个新的依赖项至现有的项目中,可以通过如下方式实现: ```bash npm install <package-name> ``` 这将会把 `<package-name>` 添加为默认的生产依赖(production dependency)。为了将其标记为开发阶段专用的依赖(development dependency),应附加 `--save-dev` 或其缩写形式 `-D`: ```bash npm install <package-name> --save-dev # 或者简化版 npm install <package-name> -D ``` 上述操作还会同步修改 `package.json` 的内容,在对应的字段里记录新加入的模块及其版本号信息。 --- #### 4. **常见错误及修复措施** ##### (a) 版本冲突问题 有时可能会遇到因不同子依赖间存在互相矛盾的需求而导致无法顺利完成构建的情况。此时可利用 `resolutions` 字段或者专门插件协助解决此类难题[^3]。 ##### (b) 缓存相关的问题 对于某些由于网络传输等原因引发的数据损坏状况,清空缓存往往能起到立竿见影的效果: ```bash npm cache clean --force ``` 之后再重试原定计划内的依赖加载流程。 ##### (c) 权限不足引起的阻碍 假如是在类 Unix 平台上遭遇权限方面的麻烦,比如试图向受保护路径写入文件失败的话,那么调整相应的访问控制设定将是必要的步骤之一;当然也可以切换成以管理员身份运行终端窗口来进行规避。 --- #### 5. **其他实用技巧** - 若要忽略可选依赖而加快整个过程的速度,只需加上标志位 `--no-optional` 即可。 - 当前工作区已经包含了完整的 lockfile 数据结构时,强制依据那份精确描述来重建全部组件集合显得尤为重要,这时需要用到选项 `--prefer-offline` 和/或 `--frozen-lockfile`。 --- ```python import subprocess def run_npm_install(): try: result = subprocess.run(['npm', 'install'], check=True, text=True, capture_output=True) print(result.stdout) except subprocess.CalledProcessError as e: print(f"An error occurred during installation:\n{e.stderr}") run_npm_install() ``` 以上脚本展示了如何借助 Python 调用外部 shell 执行 `npm install` 动作的一个简单例子。 ---
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值