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

WSL2环境下Laravel项目执行npm install遇EISDIR等错误求助

问题背景

在WSL2的Ubuntu-22.04环境中搭建Laravel应用,已安装nodejs v18.16.0、npm v9.6.6。通过curl创建Laravel项目并启动Sail,安装laravel/breeze后执行npm install时出现EISDIR目录操作错误、EPERM权限错误。

操作命令:

jdoe@Grieg:~/DevProjects/litenotes$ curl -s https://laravel.build/litenotes | bash
...
jdoe@Grieg:~/DevProjects/litenotes$ ./vendor/bin/sail up

另一终端:

jdoe@Grieg:~/DevProjects/litenotes$ ./vendor/bin/sail composer require laravel/breeze --dev
...
jdoe@Grieg:~/DevProjects/litenotes$ ./vendor/bin/sail artisan breeze:install
...
jdoe@Grieg:~/DevProjects/litenotes$ npm install

错误信息:

npm WARN cleanup Failed to remove some directories [
npm WARN cleanup   [
npm WARN cleanup     '\\wsl.localhost\\Ubuntu-22.04\\home\\jdoe\\DevProjects\\litenotes\\node_modules\\.bin\\he',
npm WARN cleanup     [Error: EISDIR: illegal operation on a directory, lstat '\wsl.localhost\Ubuntu-22.04\home\jdoe\DevProjects\litenotes\node_modules\.bin\he'] {
npm WARN cleanup       errno: -4068,
npm WARN cleanup       code: 'EISDIR',
npm WARN cleanup       syscall: 'lstat',
npm WARN cleanup       path: '\\wsl.localhost\\Ubuntu-22.04\\home\\jdoe\\DevProjects\\litenotes\\node_modules\\.bin\\he'
npm WARN cleanup     }
npm WARN cleanup   ],
npm WARN cleanup   [
npm WARN cleanup     '\\wsl.localhost\\Ubuntu-22.04\\home\\jdoe\\DevProjects\\litenotes\\node_modules\\.bin\\autoprefixer',
npm WARN cleanup     [Error: EISDIR: illegal operation on a directory, lstat '\wsl.localhost\Ubuntu-22.04\home\jdoe\DevProjects\litenotes\node_modules\.bin\autoprefixer'] {
npm WARN cleanup       errno: -4068,
npm WARN cleanup       code: 'EISDIR',
npm WARN cleanup       syscall: 'lstat',
npm WARN cleanup       path: '\\wsl.localhost\\Ubuntu-22.04\\home\\jdoe\\DevProjects\\litenotes\\node_modules\\.bin\\autoprefixer'
npm WARN cleanup     }
npm WARN cleanup   ],
npm WARN cleanup   [
npm WARN cleanup     '\\wsl.localhost\\Ubuntu-22.04\\home\\jdoe\\DevProjects\\litenotes\\node_modules\\tailwindcss',
npm WARN cleanup     [Error: EPERM: operation not permitted, rmdir '\wsl.localhost\Ubuntu-22.04\home\jdoe\DevProjects\litenotes\node_modules\tailwindcss\lib'] {
npm WARN cleanup       errno: -4048,
npm WARN cleanup       code: 'EPERM',
npm WARN cleanup       syscall: 'rmdir',
npm WARN cleanup       path: '\\wsl.localhost\\Ubuntu-22.04\\home\\jdoe\\DevProjects\\litenotes\\node_modules\\tailwindcss\\lib'
npm WARN cleanup     }
npm WARN cleanup   ]
npm WARN cleanup ]
npm ERR! code EISDIR
npm ERR! syscall lstat
npm ERR! path \wsl.localhost\Ubuntu-22.04\home\jdoe\DevProjects\litenotes\node_modules\.bin\autoprefixer
npm ERR! errno -4068
npm ERR! EISDIR: illegal operation on a directory, lstat '\wsl.localhost\Ubuntu-22.04\home\jdoe\DevProjects\litenotes\node_modules\.bin\autoprefixer'

npm ERR! A complete log of this run can be found in: C:\Users\psalm\AppData\Local\npm-cache\_logs\2023-05-14T05_45_26_819Z-debug-0.log

解决方案

1. 切换到WSL2原生终端执行命令

不要在Windows的CMD/PowerShell中操作WSL文件系统的项目,打开WSL2的Ubuntu终端,进入项目目录:

cd ~/DevProjects/litenotes

2. 清理残留文件与缓存

彻底删除现有依赖目录、锁文件并清理npm缓存:

rm -rf node_modules package-lock.json
npm cache clean --force

3. 修复目录权限(可选)

若存在权限问题,调整项目目录所属用户:

sudo chown -R $USER:$USER ~/DevProjects/litenotes

4. 重新安装依赖

在WSL终端内重新执行安装命令:

npm install

5. 确保使用WSL本地的node/npm版本

验证当前终端使用的是WSL原生的node/npm:

which node
# 正常输出应为 /usr/bin/node 类路径
node -v
npm -v

若输出为Windows路径(如/mnt/c/Program Files/nodejs/node),需调整WSL的PATH优先级,确保本地工具优先调用。

6. 避免跨文件系统存放项目

不要将Laravel项目放在Windows NTFS文件系统(如/mnt/c/Users/...),建议放在WSL原生文件系统(~/目录下),可彻底避免跨文件系统的权限与兼容性问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 13:52:48