You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel安装maatwebsite/excel报错,求解决方法及替代方案

解决Laravel安装maatwebsite/excel时的文件锁定错误

在最新版Laravel项目中执行 composer require maatwebsite/excel 时,出现多个依赖包安装失败的问题,核心错误为文件被杀毒软件或Windows搜索索引器锁定,无法删除指定文件。以下是具体解决方案和替代方案:

一、直接解决文件锁定问题

  • 临时关闭杀毒软件:安装期间暂时禁用Windows Defender或第三方杀毒软件,完成后重新开启。
  • 暂停Windows搜索索引器:
    1. 按下Win+R,输入 services.msc 打开服务管理器
    2. 找到「Windows Search」服务,右键选择「停止」
    3. 执行完Composer安装命令后,再右键选择「启动」恢复服务
  • 清理Composer缓存:先执行 composer clear-cache,再重新运行安装命令
  • 手动删除锁定文件后重试:找到错误提示中的路径 C:\Users\return\Desktop\task_project_crud/vendor/composer/389c7ae0\ezyang-htmlpurifier-bbc513d\library\HTMLPurifier\EntityLookup,手动删除该文件或整个目录,再重新执行 composer require maatwebsite/excel
  • 用管理员权限运行命令行:右键命令提示符或PowerShell,选择「以管理员身份运行」后执行安装命令

二、替代方案

如果上述方法都无效,可尝试以下替代方式:

  • 手动下载安装依赖:
    1. 下载maatwebsite/excel对应版本的源码
    2. 将解压后的文件放入项目 vendor/maatwebsite/excel 目录
    3. 执行 composer dump-autoload 生成自动加载文件,或手动处理phpoffice/phpspreadsheet等底层依赖
  • 换用其他Excel处理包:
    • 直接使用 phpoffice/phpspreadsheet(maatwebsite/excel的底层依赖包)处理Excel操作
    • 尝试安装旧版本的maatwebsite/excel,比如执行 composer require maatwebsite/excel:3.1.40,可能避开特定版本的文件锁定问题

完整错误日志

composer require maatwebsite/excel
./composer.json has been updated
Running composer update maatwebsite/excel
Loading composer repositories with package information
Updating dependencies
Lock file operations: 7 installs, 0 updates, 0 removals
 - Locking composer/semver (3.4.0)
 - Locking ezyang/htmlpurifier (v4.17.0)
 - Locking maatwebsite/excel (3.1.51)
 - Locking maennchen/zipstream-php (3.1.0)
 - Locking markbaker/complex (3.0.2)
 - Locking markbaker/matrix (3.0.1)
 - Locking phpoffice/phpspreadsheet (1.29.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 7 installs, 0 updates, 0 removals
 - Downloading markbaker/matrix (3.0.1)
 - Downloading markbaker/complex (3.0.2)
 - Downloading maennchen/zipstream-php (3.1.0)
 - Downloading ezyang/htmlpurifier (v4.17.0)
 - Downloading phpoffice/phpspreadsheet (1.29.0)
- Downloading composer/semver (3.4.0)
- Downloading maatwebsite/excel (3.1.51)
0/7 [>---------------------------]   0%
1/7 [====>-----------------------]  14%
2/7 [========>-------------------]  28%
4/7 [================>-----------]  57%
6/7 [========================>---]  85%
7/7 [============================] 100%
- Installing markbaker/matrix (3.0.1): Extracting archive
- Installing markbaker/complex (3.0.2): Extracting archive
- Installing maennchen/zipstream-php (3.1.0): Extracting archive
- Installing ezyang/htmlpurifier (v4.17.0): Extracting archive
Install of ezyang/htmlpurifier failed
- Installing phpoffice/phpspreadsheet (1.29.0): Extracting archive
 Install of phpoffice/phpspreadsheet failed
- Installing composer/semver (3.4.0): Extracting archive
- Installing maatwebsite/excel (3.1.51): Extracting archive
  Install of maatwebsite/excel failed
 0 [>---------------------------]    0 [->--------------------------]
 In Filesystem.php line 284:

 Could not delete C:\Users\return\Desktop\task_project_crud/vendor/composer/389c7ae0\ezyang-htmlpurifier-bbc513d\library\HTMLPurifier\EntityLookup:
This can be due to an antivirus or the Windows Search Indexer locking the file while they are analyzed


require [--dev] [--dry-run] [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--fixed] [--no-suggest] [--no-progress] [--no-update] [--no-install] [--no-audit] [--audit-format AUDIT-FORMAT] [--update-no-dev] [-w|--update-with-dependencies] [-W|--update-with-all-dependencies] [--with-dependencies] [--with-all-dependencies] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--] [<packages>...]

内容的提问来源于stack exchange,提问作者almoontasir Moon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 05:24:57