Alberto Siurob
Alberto Siurob

Reputation: 151

Sweetalert is not running, I got an error on it's TS file

I'm giving mainteinence to an app with Angular 7.0.7 and Node 10.20.1. I were working fine, I installed long ago Sweetalert and the plugin was working fine. Yesterday my PC restarted and when I run ng serve I got this error

ERROR in node_modules/sweetalert2/sweetalert2.d.ts(277,39): error TS1005: ',' expected. node_modules/sweetalert2/sweetalert2.d.ts(277,68): error TS1011: An element access expression should take an argument. node_modules/sweetalert2/sweetalert2.d.ts(277,69): error TS1005: ';' expected. node_modules/sweetalert2/sweetalert2.d.ts(277,70): error TS1128: Declaration or statement expected. node_modules/sweetalert2/sweetalert2.d.ts(277,82): error TS1005: '(' expected.

My package.json is this

{
  "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"
  }
}

I did a lot of tricks

I went to the sweetalert file, on the error line and I found this code

/**
     * 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>;

In all cases, is the same error... What is wrong?

Upvotes: 4

Views: 12536

Answers (5)

Guilhermevrs
Guilhermevrs

Reputation: 2344

The problem most probably comes from a mismatch on the typescript version needed by sweetalert2 and the one of your project.

On your package.json you have the following:

"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

Check your package-lock.json to be sure what is the sweetalert2 version that is locked by your project (if you have no lock, it will be 9.17.2). You can go then to https://github.com/sweetalert2/sweetalert2/blob/v[THE VERSION]/package.json to check the version needed by typescript.

If you see 9.14.0, they expect as well typescript version ^3.5

Upvotes: 1

jack-wilson
jack-wilson

Reputation: 71

I have been struggling with it as well.

With these package versions it works for me.

"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"
}

Or try with these versions:

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

Upvotes: 1

ja73
ja73

Reputation: 533

try importing using CommonJS in the component like this:

const Swal = require('sweetalert2');

worked for me ;)

Upvotes: 0

Antonio
Antonio

Reputation: 161

Hello I also started facing the same issue.Found a fix for the meantime till a better solution comes.I just downgraded it.Check and see if it works for you.

npm install [email protected]

Upvotes: 4

Jordy Arnaud Garcia
Jordy Arnaud Garcia

Reputation: 19

Good, you just have to remove the 'readonly' and the application will work

Upvotes: 0

Related Questions