VSTS发布遇EMFILE错误:Angular 5应用部署Azure失败
Let's break down your issue and walk through practical fixes for this deployment error. The EMFILE: too many open files error happens because your deployment process is trying to handle more files than the system allows—looking at your log, it's stuck on a test file in node_modules, which tells me your deployment package is including way more files than it needs to.
Here are the steps to resolve this:
Deploy Only the Angular Production Build Output
Angular apps only need the contents of thedistfolder (generated byng build --prod) to run on Azure. Right now, it looks like your deployment task is trying to push the entire project directory—includingnode_modules, test files, and source code.- In your VSTS
Azure App Service Deploytask, update the Package or folder field to point to$(Build.ArtifactStagingDirectory)/dist(adjust the path if your build outputs to a different subfolder). - Double-check your build pipeline: make sure you're running
ng build --prodto generate the optimized production build, and only publishing thedistfolder as your build artifact.
- In your VSTS
Clean Up Unnecessary Files in Your Deployment Package
The error references a.d.tstest file innode_modules—there's no reason to deploynode_modulesor test files to Azure.- Add a
.deploymentfile to your project root with the following content to tell Kudu to ignore these directories:[config] project = dist/ - If you're using kuduscript, modify your deployment script to explicitly copy only the
distcontents to the Azure web app'swwwrootdirectory, skippingnode_modules,src,spec, etc.
- Add a
Temporarily Increase File Descriptor Limits (Workaround)
If you need a quick fix while you adjust your deployment setup, you can add a PowerShell task before your deployment step to increase the maximum open files limit on the Windows build agent:fsutil behavior set maxopenfiles 8192Note: This is a temporary workaround—addressing the root cause (too many files in the deployment package) is the better long-term solution.
Optimize Your Kuduscript Configuration
Since you added kuduscript and modified scripts, double-check that your deployment logic isn't recursively copying unnecessary directories. Ensure your script targets only the built static assets indistand skips development dependencies and test files.
Why This Happens
The EMFILE error occurs when the deployment process opens more files than the operating system allows. In your case, the task is trying to process every file in node_modules (which has thousands of files) along with your source code, pushing it over the limit. By trimming down the deployment package to only what's needed (the dist folder), you'll eliminate this error entirely.
内容的提问来源于stack exchange,提问作者user2502794

