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

执行ng build --prod命令构建Angular项目时遭遇"Invalid version: '15.2-15.3'"错误的技术求助

Fixing "Invalid version: '15.2-15.3'" Error in Angular Production Builds

Hey there, I’ve dealt with this exact error when running ng build --prod before—let’s get your project building again!

What’s Causing This?

This error stems from esbuild (the tool Angular uses under the hood for production builds) refusing to parse a version string that doesn’t follow Semantic Versioning (SemVer) rules. The string "15.2-15.3" is invalid because SemVer requires versions to use dots for patches/minors and hyphens only for pre-release tags (like 15.2.0-beta.1).

This bad version string is almost certainly hiding in either:

  • Your project’s own package.json (check the version or engines fields)
  • A third-party dependency’s package.json file

Step-by-Step Fixes

1. Find the Problematic Package

First, track down which package is using the invalid version:

  • Run npm ls --all in your project root, then search the output for "15.2-15.3" to spot the culprit.
  • If you use Yarn, run yarn why <package-name> once you have a suspect to confirm its origin.
  • You can also manually check node_modules folders for packages with a package.json containing the bad version string.

2. Fix the Version Issue

Depending on where the problem is:

  • Your project’s package.json: Update the invalid version string to follow SemVer. For example, replace "15.2-15.3" with ">=15.2.0 <15.4.0" if you’re defining a range, or a specific version like "15.2.0".
  • A third-party dependency:
    • Try updating the dependency to its latest version—chances are the maintainer fixed the version formatting. Run npm update <package-name> to do this.
    • If updating isn’t an option, use npm’s overrides (or Yarn’s resolutions) to force a valid version. Add this to your project’s package.json:
      "overrides": {
        "problematic-package-name": "15.2.0"
      }
      
    • If the package isn’t essential, simply remove it with npm uninstall <package-name>.

3. Clean Cache and Rebuild

Once you’ve fixed the version issue, clear any cached data to ensure no old versions linger:

  1. Run npm cache clean --force (or yarn cache clean for Yarn)
  2. Delete your node_modules folder and package-lock.json (or yarn.lock)
  3. Reinstall dependencies with npm install
  4. Try building again with ng build --prod

Bonus: Check Angular DevKit Compatibility

If the issue persists, make sure your @angular-devkit/build-angular version is compatible with your Angular core version. Mismatches here can sometimes trigger odd esbuild errors. Update it to a version that matches your Angular major/minor version with:

npm install @angular-devkit/build-angular@<your-angular-version>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.28 14:52:34