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

运行Vue项目npm run dev时出现未处理Promise拒绝错误求助

Troubleshooting "Exited with code 3" Error in Vue Project on AWS EC2

First, let’s unpack what exit code 3 typically means here: it’s a non-zero exit from a child process spawned by your Vue dev server, usually indicating a failure during initialization, dependency loading, or compilation. Since your project works locally but fails on EC2, let’s walk through the most likely fixes:

1. Ensure Dependencies Are Fully and Correctly Installed

Even if you’re using the same Node version, EC2’s environment might have missing or corrupted dependencies. Try these steps:

  • Delete node_modules, package-lock.json (or yarn.lock) from your EC2 instance:
    rm -rf node_modules package-lock.json
    
  • Reinstall dependencies with strict versioning and no optional packages (to avoid platform-specific mismatches):
    npm install --no-optional --force
    
  • Verify that all dependencies listed in package.json are compatible with your Node version on EC2. Some packages might have hidden version constraints that only surface on Linux.

2. Fix File/Directory Permissions

AWS EC2’s ubuntu user often lacks write access to certain directories, which can break the dev server’s ability to create temporary files or compile assets:

  • Check the ownership of your project folder:
    ls -la /home/ubuntu/loan-vue-frontend
    
  • If files are owned by root, change ownership to your ubuntu user:
    sudo chown -R ubuntu:ubuntu /home/ubuntu/loan-vue-frontend
    
  • Avoid running npm commands with sudo unless absolutely necessary—this can create root-owned files that cause permission issues later.

3. Check for Missing Environment Variables

Your local setup might have a .env file with critical configuration (like API endpoints, keys) that wasn’t deployed to EC2:

  • Create a .env file in your EC2 project directory matching your local one (ensure sensitive data is handled securely, e.g., using AWS Secrets Manager instead of hardcoding).
  • Verify that all variables referenced in your Vue project (like process.env.VUE_APP_API_URL) are set correctly on EC2. You can print environment variables with:
    printenv | grep VUE_APP_
    

4. Match Node and npm Versions Exactly

Even minor differences in npm versions can cause dependency resolution issues. Use nvm (Node Version Manager) to lock in the exact Node and npm versions from your local setup:

  • Install nvm on EC2:
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
    
  • Restart your terminal, then install your local Node version (6.11.3):
    nvm install 6.11.3
    nvm use 6.11.3
    
  • Confirm the versions match your local machine:
    node -v && npm -v
    

5. Get Full Error Logs

The truncated error message you shared doesn’t show the full stack trace. Run the dev command with verbose logging to get more details:

npm run dev --verbose

This will reveal exactly which child process is failing and why—whether it’s a Webpack compilation error, a missing module, or a configuration issue.

6. Check for Platform-Specific Code

Your project might have code that works on macOS/Windows but breaks on Linux (EC2):

  • Look for hardcoded file paths using backslashes (\) instead of forward slashes (/).
  • Check if any dependencies rely on OS-specific binaries (e.g., node-sass has different builds for Linux vs macOS). For node-sass, you might need to rebuild it on EC2:
    npm rebuild node-sass
    

Start with these steps, and the full verbose logs should point you to the exact root cause.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:12:03