【问题标题】:How to find the angular Invalid version 15.2-15.3 error?如何找到 angular Invalid version 15.2-15.3 错误?
【发布时间】:2022-06-28 13:26:08
【问题描述】:

我使用 Angular CLI 13.0.4 创建了一个新的 Angular 应用程序。它创建了一个 Angular 应用程序版本 ~13.0.0。当我使用命令ng build 时,出现以下错误:

./node_modules/css-loader/dist/runtime/api.js - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
Transform failed with 1 error:
error: Invalid version: "15.2-15.3"

./node_modules/css-loader/dist/runtime/noSourceMaps.js - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
Transform failed with 1 error:
error: Invalid version: "15.2-15.3"

这些是我使用的不同版本:

我应该怎么做才能修复这个错误?

----- 2022 年 3 月 2 日更新 ------

浏览器列表文件的内容:

# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries

# For the full list of supported browsers by the Angular framework, please see:
# https://angular.io/guide/browser-support

# You can see what browsers were selected by your queries by running:
#   npx browserslist

last 1 Chrome version
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major versions
last 2 iOS major versions
Firefox ESR

【问题讨论】:

标签: angular-cli


【解决方案1】:

我从.browserslistrc 文件中注释掉了last 2 Safari major versions 行。 npm build 正在成功构建应用程序。

【讨论】:

  • 这行得通,但我需要 Safari 支持...
  • 已修复。但我想知道为什么会这样?
  • 它看起来像 @angular-devkit/build-angular 的版本,regarding the issue
  • 更新最新版本的 build-angular 为我解决了这个问题。
【解决方案2】:

尝试npm audit fixnpm audit fix --force,因为“错误:无效版本:“15.2-15.3””此错误是由于安装了无效版本,因此在 npm@6 中引入审计修复将自动解决依赖问题.

【讨论】:

  • npm audit fix --force 工作
  • 我又得到了错误,解决方案又起作用了
  • 如果它也对你有用,那就太好了
【解决方案3】:

我必须在更新 .browserslistrc 后运行 npm audit fix --force,它对我有用。

How to find the angular Invalid version 15.2-15.3 error

【讨论】:

    【解决方案4】:

    “npm audit fix”命令对我有用

    【讨论】:

      【解决方案5】:

      我从 .browserslistrc 文件中删除了最后两个 Safari 主要版本,之后构建成功创建。

      删除最后两个 Safari 主要版本后:

      【讨论】:

        【解决方案6】:

        将此库更新到最新的主要版本,它应该可以解决此问题

        yarn add @angular-devkit/build-angular -D
        

        如果您使用 Angular 13,例如运行这个命令

        yarn add @angular-devkit/build-angular@13.3.7 -D
        

        或同样使用 npm

        npm i --save-dev @angular-devkit/build-angular@13.3.7
        

        【讨论】:

          【解决方案7】:

          我在更新浏览器列表后遇到了这个问题,npm update 为我解决了这个问题。

          正如 Angular 合作者 here 所解释的那样:

          这只是Safari浏览器版本解析逻辑的一个BUG

          【讨论】:

            【解决方案8】:

            你可以简单地添加

            not ios_saf 15.2-15.3
            not safari 15.2-15.3
            

            在项目的.browserslistrc 文件中

            【讨论】:

              猜你喜欢
              • 2022-12-24
              • 2022-10-05
              • 1970-01-01
              • 2018-12-10
              • 2018-11-29
              • 1970-01-01
              • 1970-01-01
              • 2020-06-10
              • 2020-01-21
              相关资源
              最近更新 更多