Ways to incorporate StropheJs into Angular 8

Methods I have attempted:

Method 1:

  1. Downloaded the strophejs-1.3.4.zip from

  2. Unzipped the folder, strophejs-1.3.4, and placed it in the src/assets directory of my Angular 8 project.

  3. Included the following in my index.html file:

<!--// Strophe.js-->
  <script src='assets/strophejs-1.3.4/src/strophe.js'></script>
  1. Installed @types/strophe using the command:

    npm install --save-dev @types/strophe

  2. Declared let Strophe: any; in my component.ts file

Despite successfully compiling after these steps, when running the code, a runtime reference error is encountered:

Reference Error: Strophe is not defined

Below is the content of my component.ts file:

import { Component, OnInit } from '@angular/core';

declare let Strophe: any;

@Component({
  selector: 'app-oauth',
  templateUrl: './oauth.component.html',
  styleUrls: ['./oauth.component.scss']
})
export class OauthComponent implements OnInit {

  constructor() { }

  ngOnInit() {
    const connection = new Strophe.Connection('http://localhost:5280/bosh');
    // connection.rawInput = rawInput;
    // connection.rawOutput = rawOutput;

    connection.connect('user@localhost', 'password', this.onConnect);
  }

  onConnect(status) {
    if (status == Strophe.Status.CONNECTING) {
      console.log('Strophe is connecting.');
    } else if (status == Strophe.Status.CONNFAIL) {
      console.log('Strophe failed to connect.');
    } else if (status == Strophe.Status.DISCONNECTING) {
      console.log('Strophe is disconnecting.');
    } else if (status == Strophe.Status.DISCONNECTED) {
      console.log('Strophe is disconnected.');
    } else if (status == Strophe.Status.CONNECTED) {
      console.log('Strophe is connected.');
    }
  }
}

Method 2:

  1. Installed npm package strophejs (though hesitant due to deprecation warning) using the command npm i strophe from https://www.npmjs.com/package/strophe

  2. Encountered difficulty importing it in my component.ts file. :(

P.S An error (

Exports and export assignments are not permitted in module augmentations.
) appeared in the index.d.ts file of @types/strophe:

declare module "Strophe" {
   export = Strophe;
   ^^^^^^
 }

To resolve this issue, I consulted the following resources:

  1. Exports and export assignments are not permitted in module augmentations - Uncertain how to apply this solution in my case

  2. Typescript error "An export assignment cannot be used in a module with other exported elements." while extending typescript definitions - Attempted but unsuccessful

  3. Tried the recommended fix in this https://github.com/apexcharts/apexcharts.js/issues/577, however, it did not work either.

Answer №1

If you're considering using the Strophe npm package, keep in mind that it is now deprecated and not recommended for use. Instead, I discovered how to utilize the downloaded file directly from

Follow these steps:

  1. Go to the location where the file was downloaded.

  2. Run npm install within that directory. This will create a dist folder containing two files and a folder.

  3. Take the Strophe.umd.min.js file from the /dist/Strophe.umd.js folder and place it in your angular project's /assets folder.

  4. Add the path to this file in your angular.json configuration file.

"scripts": [
              "src/assets/strophe.umd.min.js"
            ]

Make sure to adjust the path according to the recommendation mentioned by @canbax in his answer.

Answer №2

In order to utilize an npm package within your project, you will need to make modifications to the angular.json file by navigating to

projects>your-project-name>architect>build>options>scripts
. This specific section is located deep within the JSON structure.

"scripts": [
              "node_modules/jquery/dist/jquery.js",

For a standard JavaScript library such as jQuery, you can import it in a TypeScript file like so:

import * as $ from 'jquery';

However, integrating this with types and typing support may introduce complexity.

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

Encountering an issue with the message: "Property 'ref' is not available on the type 'IntrinsicAttributes'."

Having trouble implementing a link in React and TypeScript that scrolls to the correct component after clicking? I'm using the useRef Hook, but encountering an error: Type '{ ref: MutableRefObject<HTMLDivElement | null>; }' is not assi ...

Tips for streamlining IF statements with multiple conditions

When looking at various code samples, I often see something like this: if(X == x && A == a){ } else if (X == y && A == b){ } else if (X == z && A == c){ } else if (X == zz && A == d){ } Alternatively, there are conditions ...

Retrieving selected values from a dynamic Primeng checkbox component

Within my Angular app, I am managing an array of questions. Each question includes a text field and an array of string options to choose from. The questions are retrieved dynamically from a service and can be updated over time. To allow users to select mul ...

The combination of both fullWidth and className attributes on a Material-UI component

I am facing an issue with using both the className and fullWidth properties on a Material UI TextField component. It seems that when trying to apply both, only the className is being recognized. When I use just the className or just the fullWidth property ...

What is the proper way to indicate that a function parameter corresponds to one of an Interface's keys?

When working with TypeScript, I am looking for a way to validate that the argument passed to myFunction matches one of the keys defined in MyInterface. Essentially, I want to enforce type checking on the arg parameter as shown below. export interface MyInt ...

Angular 9: Implementing a synchronous *ngFor loop within the HTML page

After receiving a list of subjects from the server, exercises are taken on each subject using the subject.id (from the server) and stored all together in the subEx variable. Classes are listed at the bottom. subjects:Subject[] temp:Exercise[] = [] s ...

Sending the id from a component to a service in Angular

In my current project, I am working on a chat application using Angular with WebSocket integration. Let me provide an overview of the architecture I have designed for this project. I created a module called 'chatting' which contains a list of use ...

The absence of Index.ts in the TypeScript compilation cannot be resolved by simply including it

Upon integrating @fireflysemantics/slice into my Angular project, I encountered the following error: ERROR in ./node_modules/@fireflysemantics/slice/index.ts Module build failed (from ./node_modules/@ngtools/webpack/src/index.js): Error: /home/ole/Temp/fs ...

A guide to linking various choices/dropdowns in Angular version 4

Let me explain my situation the best I can. I have a search filter that works perfectly in Angular 4 when used in this format: <select [(ngModel)]="city_filter" (change)="applyFilter('city',$event.target.value)"> <option value="Ahmedab ...

Attempting to transpile JavaScript or TypeScript files for compatibility within a Node environment

Our node environment requires that our JavaScript files undergo Babel processing. Figuring out how to handle this has been manageable. The challenge lies in the fact that we have a mix of file types including .js, .jsx, .ts, and .tsx, which is not subject ...

Access specific files within a workspace in VS Code with read-only permissions

Currently, I am engaged in a typescript project within Visual Studio Code. In my workflow, a gulp task is responsible for transferring code to a designated folder. The files copied will be utilized by corresponding files located in the destination folder t ...

Encountering a bug in Angular 11 while fetching data from the backend to display on the screen - facing an issue with trying to access property 'values' of an undefined variable

I am currently working on retrieving data from the backend/api and attempting to display it using *ngFor. However, I am encountering the following errors: Cannot read property 'values' of undefined Below are the components, service codes, and ...

I am experiencing issues with Angular routing as it keeps redirecting me back to the main base url

Currently, I am attempting to utilize the angular router in order to navigate from one page to another. Within my page, there is a button that, upon clicking, should direct me to a different page. At this moment, my URL reads as: http://localhost:4200/us ...

Hey there world! I seem to be stuck at the Loading screen while trying to use Angular

A discrepancy in the browsers log indicates node_modules/angular2/platform/browser.d.ts(78,90): error TS2314: Generic type 'Promise' is missing 2 type arguments. ...

Is it better to use interpolation and template expressions within *ngFor or *ngIf directives?

I am encountering challenges when attempting to interpolate variables within ngFor or ngIf in my code. My components are highly dynamic, both in terms of content and functionality, which is why I need to perform such operations. I believe it should be pos ...

How to work with JSON containing numerical variable names in TypeScript

Looking at the JSON data from Swagger, I noticed that there are response codes represented as numbers in the "responses" section. For example, the responses include 200, 404, and 503 along with their descriptions. "responses": { "200": { "descriptio ...

Execute a function in the background, even if the browser has been shut down

Is it possible to run a JavaScript function in the background, even after the user has closed the browser? I know this can be achieved in android apps, but I'm not sure about JavaScript. ...

How can I retrieve the decimal x and y coordinates when the mouse is moved in Typescript Angular?

I am in the process of transitioning my user interface from Flash/Flex, where it stores values in decimal format. I need to access and reuse these values. Here is a demo showcasing my problem. Here is a snippet: import { Component, Input } from '@an ...

Attempting to test a Jasmine directive in Angular results in failure

After creating a simple directive that throws an error when the input is invalid, I encountered an issue with my testing. When attempting to test for the thrown error using expect().toThrow(), it succeeded as expected. However, the same result occurred w ...

Growing the number of items in the shopping cart

I am facing challenges in adjusting the quantities of products in my cart after adding them. Let me explain the process step by step. 1- I list out the products. 2- I create a function to abbreviate the quantities (miktarKisalt) 3- If the products can b ...