Next.js项目执行npm run build时触发EPERM权限错误求助
解决Next.js项目npm run build时的EPERM权限错误
项目信息
以下是名为portfolio的Next.js项目的package.json内容:
{ "name": "portfolio", "version": "0.1.0", "private": true, "scripts": { "postinstall": "prisma generate", "dev": "next dev", "build": "next build", "start": "next start", "lint": "next lint", "lint:fix": "eslint --fix ." }, "dependencies": { "@prisma/client": "^5.12.1", "next": "14.2.2", "next-themes": "^0.3.0", "prisma": "^5.12.1", "react": "^18", "react-dom": "^18", "react-icons": "^5.1.0", "sharp": "^0.33.3" }, "devDependencies": { "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", "eslint": "^8.57.0", "eslint-config-next": "^14.2.2", "postcss": "^8", "prettier": "^3.2.5", "prettier-plugin-tailwindcss": "^0.5.14", "tailwindcss": "^3.4.1", "typescript": "^5" } }
构建错误信息
执行npm run build时出现权限错误:
PS R:\Projects\new-portfolio> npm run build > portfolio@0.1.0 build > next build ▲ Next.js 14.2.2 - Environments: .env Creating an optimized production build ... glob error [Error: EPERM: operation not permitted, scandir 'C:\Users\Ravi\Application Data'] { errno: -4048, code: 'EPERM', syscall: 'scandir', path: 'C:\\Users\\Ravi\\Application Data' } Failed to compile. Error: EPERM: operation not permitted, scandir 'C:\Users\Ravi\Application Data' > Build failed because of webpack errors
解决方法
以管理员身份运行终端
右键PowerShell或CMD,选择「以管理员身份运行」,切换到项目目录后重新执行npm run build。清理缓存后重新构建
依次执行以下命令:npm cache clean --force rd /s /q .next node_modules npm install npm run build检查项目路径与目录权限
确保项目路径(R:\Projects\new-portfolio)无特殊字符或空格;右键C:\Users\Ravi文件夹,进入「属性」→「安全」,确认当前用户拥有该目录的读取、执行权限,必要时添加完全控制权限。排查自定义webpack配置
如果项目有自定义next.config.js,检查是否错误地将用户目录纳入扫描范围,调整include/exclude规则,仅限定扫描项目内部文件。检查环境变量与.env文件
确认.env文件中的变量未指向无权限访问的路径,环境变量(如NODE_ENV)配置正常。
内容的提问来源于stack exchange,提问作者Ravishankar Jha
相关产品推荐
相关产品推荐

