Sweetalert seems to have hit a roadblock and is not functioning properly. An error has been detected in its TS file

Currently, I am responsible for maintaining an application that utilizes Angular 7.0.7 and Node 10.20.1. Everything was running smoothly until yesterday when my PC unexpectedly restarted. Upon trying to run ng serve, I encountered the following 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.

The content of my package.json file is as follows:

{
  "name": "frontend",
  "version": "0.0.0",
  ... (package.json content continues here)
}

In attempting to resolve this issue, I have tried several troubleshooting methods:

  • I uninstalled and reinstalled all node modules using npm install, but the issue persisted.
  • Downgrading TypeScript to version 2.X did not resolve the problem either.
  • Reinstalling just Sweetalert using
    npm uninstall sweetalert2 && npm install sweetalert2
    also proved unsuccessful.
  • Running npm audit fix highlighted numerous issues within the app, none of which resolved the original error.

Examining the Sweetalert file at the specified error line, I came across the following code snippet:

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

Despite trying various solutions, the error remained consistent... What could be causing this issue?

Answer №1

Hey there! I encountered a similar issue recently and managed to find a temporary solution while we wait for a more permanent fix. I decided to downgrade the software, and surprisingly it worked. Give it a try and see if it resolves the problem for you too.

To perform the downgrade, simply run this command in your terminal: npm install [email protected]

Answer №2

I've also been facing some challenges with it.

But I found that using these specific versions of the packages made it work 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"
}

Alternatively, you could give a shot to these different versions:

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

Answer №3

The issue likely arises from a mismatch in the required typescript version between sweetalert2 and your project.

Your package.json contains the following:

"sweetalert2": "^9.14.0" // Requires versions like 9.X where X is >= 14
"typescript": "~3.1.6" // Requires versions like 3.1.Y where Y is >= 6

Verify the sweetalert2 version locked by your project in the package-lock.json (if no lock file, default to 9.17.2). Next, visit

https://github.com/sweetalert2/sweetalert2/blob/v[THE VERSION]/package.json
to confirm the expected typescript version.

If you find 9.14.0, they also require typescript version ^3.5

Answer №4

Great job! All you need to do is delete the 'readonly' property and your app will be up and running smoothly

Answer №5

If you want to import using CommonJS in your component, you can do it like this:

const SweetAlert = require('sweetalert2');

This method worked perfectly for me! 😊

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Influence of Getter Performance in Angular Templates

As I delve into an existing Angular application, I've noticed a pattern where values used in templates across many components are actually properties that are being accessed through getters and setters without any additional logic: <input type="nu ...

Mapping Observable.forkJoin() responses to the respective requests can be achieved by following these steps

I have a tool that uses the httpClient to generate response observables for a pipe. I also have a collection of request URLs. This is how the code appears: let observables = urls.map(url=>myPipe.transform(url)); forkJoin(observables).subscribe(results=& ...

"Encountered a 'NextAuth expression cannot be called' error

Recently, I delved into learning about authentication in Next.js using next-auth. Following the documentation diligently, I ended up with my app/api/auth/[...nextauth]/route.ts code snippet below: import NextAuth, { type NextAuthOptions } from "next-a ...

What is the best way to arrange map elements in a React application?

I am trying to implement filter buttons for low to high rates and high to low rates, but I am having trouble figuring it out. How can I apply the filter to display the data accordingly? The data that needs to be filtered is stored in rate.retail_rate. ty ...

An easy method to define argument types for every function type in TypeScript

How can I assign argument types to each function type in TypeScript? Each function has a parameter associated with it. [Example] type F1 = (arg: number) => void; type F2 = (arg: string) => void; const caller = (f: F1 | F2) => (n: number | strin ...

Angular 4: Utilizing reactive forms for dynamic addition and removal of elements in a string array

I am looking for a way to modify a reactive form so that it can add and delete fields to a string array dynamically. Currently, I am using a FormArray but it adds the new items as objects rather than just simple strings in the array. Here is an example of ...

Utilizing group by date feature in Angular ag-Grid

I'm working on setting up an ag-grid with columns for date, time, and location. Below is the code snippet: list.component.ts columnDefs: any = [{ headerName: 'Date', field: 'date', valueFormatter: (data: any) => { ...

The production output for the Wp-strap WordPress plugin boilerplate appears to be blank

I am interested in utilizing the WordPress plugin boilerplate available at https://github.com/wp-strap/wordpress-plugin-boilerplate to develop Wordpress plugins. The challenge I'm facing is that running yarn prod results in empty output (the css file ...

Why was the Project directory not found? To resolve this issue and restart Next.js in a new directory, an error occurred during the npm run dev command on the front

When I updated my project by replacing the public and source folders with those from Git, I made sure to create a new .env file in my project directory containing my client's Google token. Additionally, I integrated Tailwind CSS with Next.js and confi ...

Scroll horizontally in Ionic 3 without displaying the scrollbar by implementing a button

Is there a way to implement ion scroll in such a manner that upon clicking the right arrow button, it smoothly transitions to the next element within the div section of ion content in Ionic 3 without displaying any scrollbar? I want the scrollbar to remain ...

The occurrence of a loading error arises when attempting to load the second component, displaying the message 'The template instructed for component SidebarComponent is

My journey with Angular has just begun, and I decided to challenge myself by creating a simplistic dashboard. In order to achieve this, I developed two components called DashboardComponent and SidebarComponent. The DashboardComponent loads smoothly witho ...

The specified module '...' is identified as a non-module entity and therefore cannot be imported using this specific construct

Currently, I am facing an issue in my .tsx file where I am attempting to import a RaisedButton component from material-ui using the following code: import * as RaisedButton from 'material-ui/lib/raised-button' Unfortunately, this is triggering ...

Having trouble with npm commands on Ubuntu?

After setting up node and npm on my Ubuntu 14.04 system, I encountered a problem when trying to run npm commands. The error message that popped up is as follows: /usr/local/lib/node_modules/npm/lib/config/cmd-list.js:113 module.exports.aliases = Object.as ...

Experiencing an issue with my Angular 6.1.0 setup, using angular-cli 7 and primeng 7 - specifically encountering the error message "Initializers are not allowed in ambient context."

Issue encountered in the primeng package: While examining node_modules/primeng/components/picklist/picklist.d.ts, errors were found at line numbers 65 and 66. I have investigated the primeng package further. primeng/components/picklist/picklist.d.ts l ...

Utilize VUE NPM to add imported packages to all remaining files

I am using a Vue 3 npm app and I have installed the jQuery package to use it. Currently, in order to use jQuery, I need to import it like this: import $ from "jquery"; Although this method works, I find it cumbersome as I have to include this im ...

The text inside angular spans mysteriously vanishes

I have encountered an issue while working on my Angular Project. Previously, the <span> elements were displaying their contents without any problems. However, now I am facing an issue where the contents of <Span> elements are not visible. For ...

The paths configuration in tsconfig.json is not functioning as anticipated

I've been encountering a module not found error while trying to work with jasmine-ts. To troubleshoot, I decided to use tsc and inspect my folder structure: \src\app\... \src\tests\... To address this issue, I created a ...

Unable to retrieve the updated value from the service variable

I'm attempting to implement a filter that allows me to search for items based on a service variable that is updated with user input. However, I am only able to retrieve the initial value from the service in my component. Service HTML (whatever is typ ...

Embedding and authorization

I'm currently working on incorporating the OHIF DICOM viewer into an iFrame within an Angular project. However, it seems that Google accounts are not allowed to function within an iFrame (OAuth is required with the OHIF viewer). Is there a way to enab ...

Retrieve user details from a NextJS application following a successful Keycloak authentication on a Kubernetes cluster

I've been attempting to retrieve the authenticated user information in my NextJS app after being redirected to it following a successful Keycloak login on a different tab located at localhost:8080/auth. The ingress (entry point) is responsible for ch ...