【问题标题】:Sweetalert is not running, I got an error on it's TS fileSweetalert 没有运行,我的 TS 文件出错了
【发布时间】:2020-09-20 00:49:35
【问题描述】:

我正在维护一个使用 Angular 7.0.7 和 Node 10.20.1 的应用程序。 我工作正常,我很久以前安装了 Sweetalert,插件工作正常。昨天我的电脑重新启动,当我运行 ng serve 时出现此错误

node_modules/sweetalert2/sweetalert2.d.ts(277,39) 中的错误:错误 TS1005:“,”预期。 node_modules/sweetalert2/sweetalert2.d.ts(277,68):错误 TS1011:一个 元素访问表达式应该带一个参数。 node_modules/sweetalert2/sweetalert2.d.ts(277,69): 错误 TS1005: ';' 预期的。 node_modules/sweetalert2/sweetalert2.d.ts(277,70): 错误 TS1128:需要声明或声明。 node_modules/sweetalert2/sweetalert2.d.ts(277,82): 错误 TS1005: '(' 预计。

我的 package.json 是这个

{
  "name": "frontend",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --proxy-config proxy.conf.json",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "test2": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^7.0.4",
    "@angular/cdk": "^7.3.0",
    "@angular/common": "~7.0.0",
    "@angular/compiler": "~7.0.0",
    "@angular/core": "~7.0.0",
    "@angular/forms": "~7.0.0",
    "@angular/http": "~7.0.0",
    "@angular/material": "^7.3.0",
    "@angular/material-moment-adapter": "^9.2.3",
    "@angular/platform-browser": "~7.0.0",
    "@angular/platform-browser-dynamic": "~7.0.0",
    "@angular/router": "~7.0.0",
    "@fortawesome/fontawesome-free": "^5.13.0",
    "@sweetalert2/theme-material-ui": "^3.1.4",
    "bootstrap": "^4.2.1",
    "core-js": "^2.5.4",
    "devextreme": "^18.2.5",
    "flagkit-web": "0.0.3",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "intro.js": "^2.9.3",
    "ionicons": "^4.5.5",
    "moment": "^2.25.3",
    "ngx-bootstrap": "^5.5.0",
    "ngx-toastr": "^10.0.4",
    "pixeden-stroke-7-icon": "^1.2.3",
    "rxjs": "~6.3.3",
    "sweetalert2": "^9.14.0",
    "xlsx": "^0.15.6",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.10.0",
    "@angular/cli": "~7.0.5",
    "@angular/compiler-cli": "~7.0.0",
    "@angular/language-service": "~7.0.0",
    "@types/intro.js": "^2.4.6",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "pe7-icon": "^1.0.4",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.1.6"
  }
}

我做了很多花样

  • 删除并安装了所有带有npm install 的node_modules,没有工作
  • 我将 typescript 降级到 2.X 版本,没有用
  • 只用npm uninstall sweetalert2 && npm install sweetalert2重新安装了sweetalert,没有用
  • 我跑了npm audit fix,我收到了很多关于应用程序的问题,没有用

我去了 sweetalert 文件,在错误行,我找到了这段代码

/**
     * Provide an array of SweetAlert2 parameters to show multiple popups, one popup after another.
     *
     * @param steps The steps' configuration.
     */
    function queue<T>(steps: readonly (SweetAlertOptions | string)[]): Promise<T>;

在所有情况下,都是相同的错误... 怎么了?

【问题讨论】:

  • 你尝试升级 Angular 了吗?
  • 该应用是基于 Angular 7 构建的,客户希望仍然
  • 那么降级sweetalert2怎么样?
  • 你推荐什么版本?
  • v8.0.0 将是一个开始。

标签: angular typescript npm sweetalert2


【解决方案1】:

您好,我也开始面临同样的问题。在此期间找到了一个修复程序,直到有更好的解决方案出现。我刚刚降级了它。检查它是否适合您。

npm install sweetalert2@v9.11.0

【讨论】:

    【解决方案2】:

    我也一直在苦苦挣扎。

    使用这些软件包版本,它适用于我。

    "dependencies": {
      // ... 
      "@angular/common": "^7.2.16",
      "@angular/core": "^7.2.16",
      // ...
      "sweetalert2": "8.19.0",
      "@sweetalert2/ngx-sweetalert2": "^6.0.0",
    },
    "devDependencies": {
       "typescript": "3.2.4"
    }
    

    或者试试这些版本:

    "sweetalert2": "^8.0.0",
    "@sweetalert2/ngx-sweetalert2": "^5.0.0"
    

    【讨论】:

      【解决方案3】:

      问题很可能来自sweetalert2 和您的项目所需的打字稿版本不匹配。

      在您的 package.json 中,您有以下内容:

      "sweetalert2": "^9.14.0" // Wants any version like 9.X where X must be >= 14
      "typescript": "~3.1.6" // Wants any version like 3.1.Y where Y must be >= 6
      

      检查您的 package-lock.json 以确定您的项目锁定的 sweetalert2 版本是什么(如果您没有锁定,它将是 9.17.2)。 然后你可以去https://github.com/sweetalert2/sweetalert2/blob/v[THE VERSION]/package.json查看打字稿需要的版本。

      如果您看到 9.14.0,他们也期望 typescript 版本 ^3.5

      【讨论】:

        【解决方案4】:

        很好,您只需删除“只读”,应用程序就会运行

        【讨论】:

        • 您不能建议在本地编辑外部包。这不会解决克隆项目的人的问题。
        【解决方案5】:

        尝试在组件中使用 CommonJS 进行导入,如下所示:

        const Swal = require('sweetalert2');
        

        为我工作;)

        【讨论】:

          猜你喜欢
          • 2020-05-28
          • 1970-01-01
          • 2021-10-08
          • 2022-07-23
          • 1970-01-01
          • 2022-01-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多