sjmf / ng2-stompjs-demo

Angular 2 demo using stomp.js in Typescript
MIT License
41 stars 6 forks source link

Property 'client' does not exist on type 'typeof "stompjs"' #19

Closed cmhampton1021 closed 7 years ago

cmhampton1021 commented 7 years ago

I'm not sure if this is the best place to post this, but I'm trying to integrate this into our application and keep getting this error in the angular cli.

It happens on what is line 81 in the stomp.service.ts file (it's on a different line in mine): // Attempt connection, passing in a callback this.client = Stomp.client('${scheme}://${environment.messageQueueRootUrl}:${environment.messageQueuePort}/ws/v11.stomp'); I had this in another app developed with Angular2 RC4, and it worked perfectly. Now that I'm trying to integrate it into our new platform based on the final release of Angular2, I'm getting this error.

Any help would be appreciated.

Chris Hampton

JimiC commented 7 years ago

Your problem lies in the /ws/v11.stomp part. It has to be /stomp/websocket. I faced a similar issue when using RabbitMQ server with the stomp protocol and /ws/stomp doesn't work.

cmhampton1021 commented 7 years ago

I'm confused why that would affect the compiler though. I've updated it to:

this.client = Stomp.client('${scheme}://${environment.messageQueueRootUrl}:${environment.messageQueuePort}/stomp/websocket');

And it still fails compilation.

cmhampton1021 commented 7 years ago

Here are some screenshots. angularcli vsscreenshot

JimiC commented 7 years ago

I totally misread you there, sorry. Stomp seems not to be resolved by TS. How do you import stompjs?

JimiC commented 7 years ago

Just to make you aware, I've written the stompjs typings just for this. You can use it now in your devDependecies section of package.json like this :"@types/stompjs": "~2.3.0", and then simply import stompjs like this: import * as Stomp from 'stompjs'; in your code.

sjmf commented 7 years ago

Yep, definitely sounds like the compiler's not picking up the Stomp typings?

@cmhampton1021 Feel free to post your package.json if you still can't get it to work.

cmhampton1021 commented 7 years ago

I'm still having the same issue after adding the typings to my package.json file. I appreciate the help, I'm a little late to the party with all this node/npm stuff.

package.json.txt stomp.service.ts.txt

JimiC commented 7 years ago

@cmhampton1021 Sorry, but links don't work.

cmhampton1021 commented 7 years ago

Here's a google drive link.

https://drive.google.com/open?id=0B6sTsP

JimiC commented 7 years ago

Still not working. Better use Gist.

cmhampton1021 commented 7 years ago

https://gist.github.com/cmhampton1021/e351bbe7e9462750f3dc4e5d3b3f8451 https://gist.github.com/cmhampton1021/b245d64ce6603b7e4027c25d101e3c9b

JimiC commented 7 years ago

For every package, you use you need to declare it in dependencies section. Look at the project's package.json.

cmhampton1021 commented 7 years ago

Thanks, that seemed to work, mostly. There's apparently something weird about my computer, though. When I initially run ng serve, it fails to compile. But if I remove the service from the constructor of my app component, it recompiles and succeeds. Then I put it back in, and it still works. So it only fails when it does the initial compile.

Also, in my IDE, it still flags that line with an error. I've been using Visual Studio, so I thought that might be the problem. But after switching to Atom, that line is still flagged.

JimiC commented 7 years ago

Obviously, you are not declaring providers properly in app.module.ts of the project. Every service you want available in the project needs to be declared there. I suggest you make the effort to read the docs about Angular 2.

cmhampton1021 commented 7 years ago

I am including the service, thank you very much, and I have read the docs. providers: [ StompConfigService, STOMPService, ToastService ],

So, nevermind then. I will find another solution to this problem.