I am a beginner with Angular and TypeScript.
To get started, I used npm to install the following package:
npm install --save sockjs-client
I attempted to import it in my chat.component.ts file like this:
import * as SockJS from 'sockjs-client';
However, I encountered the following error message:
TS7016: Could not find a declaration file for module 'sockjs-client'. '/home/simon/javaprojs/tour-creator/client/node_modules/sockjs-client/lib/entry.js' implicitly has an 'any' type. Try
if it exists or add a new declaration (.d.ts) file containingnpm i --save-dev @types/sockjs-client
declare module 'sockjs-client';
In response, I tried the suggested solution:
npm i --save-dev @types/sockjs-client
Unfortunately, this resulted in a new warning:
Warning: /home/simon/javaprojs/tour-creator/client/src/app/components/chat/chat.component.ts depends on 'sockjs-client'. CommonJS or AMD dependencies can cause optimization bailouts. For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Below is the code snippet of my component:
import {Component, OnInit} from '@angular/core';
import * as Stomp from 'stompjs';
import * as SockJS from 'sockjs-client';
@Component({
selector: 'app-chat',
templateUrl: './chat.component.html',
styleUrls: ['./chat.component.css'],
})
export class ChatComponent implements OnInit {
constructor() { }
connect(): void {
const socket = new SockJS('gs-guide-websocket');
}
ngOnInit(): void {
this.connect();
}
}
What should I do next? Upon starting the application, I only see a white page with a console error stating that global is not defined.