-
Notifications
You must be signed in to change notification settings - Fork 445
SERIOUS BUG: signalr-client breaks when used with angular-cli #729
Comments
I've just tried most of what you describe in my it's-just-angular app:
It would help if you could post the actual error message |
Hi, thanks for looking at this. Our project uses angular-cli, so we don't really have the option of going back and only using webpack. I used Google Chrome on Mac, however the problem (and error messages) was the same with the main project which is on Windows. The error message which is shown in the console is
This is index.js within the package itself There are also 9 warnings from various files:
This includes: index.js, HttpConnection.js, HttpClient.js, HubConnection.js, Transports.js, HttpError.js, Observable.js, Formatters.js and JsonHubProtocol.js (all of which are in the dist folder of course). These warnings also occur in the command line (Terminal on mac, PS on Windows) The fact I used yarn shouldn't have any effect - it just loaded alpha1-26666 from the dotnet.myget feed, so it is the same. If I run ng serve--prod, the error I got was slightly different:
This error occurs on the command line, in the browser console, and angular-cli is kind enough to actually display it in the browser itself with a nice dramatic black background. |
That last error is angular/angular-cli#7113 and has nothing to do with the browser error |
The debug message will probably be more helpful; I just included prod for completeness. Obviously the software is still in alpha, but assuming that an angular-cli front end environment were to be supported I would expect it to just work. I suspect that it's not playing nicely with the default webpack configuration in angular-cli - I know it's possible to "eject" the webpack to be able to edit it, but again I would not have expected to have to do that for a single 3rd party dependency. In fact, assuming you are able to reproduce this, I suspect you will need to eject in order to work out what differences there may be in the default webpack config which fails, with your webpack setup (which works, as you say) |
If you search for the warning messages, everything points to webpack (which the angular CLI uses internally). Also a missing module suggests you have an inconsistent module state in the browser (have you been running with HMR?). I highly doubt this is an issue in signalr-client. The generated js code and the accompanying .d.ts files all look perfectly fine and also work in my angular (4.3.1) + webpack (3.3.0) build. I strongly suggest against ejecting from the angular-cli. I once saw John Papa on stage doing this and then making fun of the hundreds and hundreds of lines of webpack configuration code. If your experience hasn't told that yet: When you come from the wonderful, stable and polished world of .NET with thoroughly tested libraries and fast tooling that makes you smile all the time, then web development is a dark world of continuous pain. Here are two examples:
I suggest you ask the angular-cli team what they are doing to break using signalr-client. In a simpler webpack setup than theirs, it just works. |
Could you confirm:
One of the key advantages with angular-cli is precisely because you don't need to worry about webpack configuration or anything else. Everything just works, and the onus is usually on the component developer to make it work. I do recognise this is early stage stuff, but as things stand it doesn't seem to work with angular-cli which if not resolved would make it difficult to use signal r in many angular projects. |
@moozzyk Once you start importing and using real code like I'm by no means an expert on how js libraries should ship (there are waaaay too many options on both ends), but I just did a little experiment:
I rebuilt the .js and the .d.ts files and placed them them into the node_modules/signalr-client/dist/src folder of my actual project. These files result in a successful webpack build (and the expected failing HTTP request against my server when
This is usually when my head starts hurting... |
@Tragetaschen - does it work if you remove
|
Huh? The
|
FYI, I tried replacing the enum ref with a reference to a class, which generates more warnings in the terminal (the browser was the same)
It probably has little effect, but it might be worth pointing out that the package.json generated by ng-cli refers to @angular/cli version 1.0.0; whereas the most recent version is 1.3.0, where they've ironed out a few issues. The errors I got were the same, but that might help you if you upgrade that within the project too. The warnings were as below:
|
I've created a small reproduction: https://gist.github.com/Tragetaschen/cbff57f27c82d19fa017d753f23b3c43
When you use |
@Tragetaschen is this entry for internal use or for me to try? Are you suggesting I download the signal r repo from github? In principle, not a problem, however can you confirm if so which branch should I download? On a basic level, from our project's point of view we need to simply be able to reference the signalr-client in an angular-cli project (vanilla or otherwise) and have it not error out. You should see the problem if you install angular-cli and follow the steps I did (obviously don't worry about yarn, that's just a detail). |
@williamBurgeson I've removed angular-cli from the picture and reduced the problem to Webpack failing to handle UMD modules produced by TypeScript. When TypeScript produces The only thing I can suggest for you and your project: don't use nightly builds if want things to just work. I'm trying to give the SignalR team a simple reproduction for the mentioned problem. As I've said: the module and bundling landscape in JavaScript is very complex and building a npm package that works in many (all?) environments is a challenge many projects face. I, personally, would like signalr-client package to just work in a Webpack build (and by extension hopefully in angular-cli). |
Thanks for looking at this. As I said previously I accept that it is an early alpha build, so it will not be perfect. As for use cases, I imagine it would need to work in all major framework environments, however for us the only game in town is angular-cli, which, I suspect, although fairly new, is going to be become the default and most popular way of scaffolding angular applications in the coming months and years. |
I got it working with angular-cli and works fine in development. Only error I get when building is: ERROR in vendor.aa3432c7091a7afeab7f.bundle.js from UglifyJs |
@Marcelh1983 does it work with both ng serve and ng serve --prod? For most potential errors, I would expect ng build and ng build --prod would produce the same errors, were they to occur |
@williamBurgeson ng serve --prod also fails. without --prod it runs fine. it probably has to do with the way I import types. When I import like this:
I get a lot of warnings first: WARNING in ./node_modules/signalr-client/dist/src/index.js And eventually: ERROR in vendor.c7bbaffc8012e19b81ad.bundle.js from UglifyJs |
@Marcelh1983 thanks for the progress. You'll probably be aware but in general I think the protocol is that you import types from the top level of a 3rd party dependency, rather than deep-linking. rxjs is an exception to this of course... |
@williamBurgeson - I think I have a fix that fixes webpack errors when using @Marcelh1983 - I could reproduce this error:
It seems it is because UglifyJs does not support ES6 |
The fix is in 0.1.0-alpha1-26727 or newer. The UglifyJs issue is external. |
I have downloaded version 26733 I uncommented the import statement at the top of the file and included the following code in my service (which is just for starters obviously):-
I ran
which is from Transports.js line 27 At least at first glance this seems to be working, so I move on from here. When I tried running I will update if I encounter any further related issues in the dev build |
Have we got ng build --prod working? If not I will open another issue. There's also one or two other things I will look at and possibly raise. |
@williamBurgeson - As explained above |
This is what I did to be able to use this package in production:
Seems to work |
@Marcelh1983 thanks for this, obviously ejecting is something I'd prefer to avoid, however if changes are needed within the build environment for it to work then I suppose I could raise an enhancement with the angular-cli project to allow certain things to be more flexible. I'll also talk to my managers about finding the time to understand exactly what other external projects do to ensure they are able to ork with angular-cli with no problem. |
I have raised this with the angular-cli team: angular/angular-cli#7532 |
See the latest update, they are considering enhancing uglify to support es6: angular/angular-cli#7532 (comment) Although this isn't under the signalR team's control, until they fix this we can't really deem signalr-client to be angular-cli production ready |
Belatedly, I can confirm that the fix proposed in angular/angular-cli#7610 works - I currently have @angular/cli 1.5.0-beta.2 in my environment (I'm not sure if 1.4.4 will work) |
Angular-cli has updated 1.5.0. It's solved this problem. Current version of @aspnet/signalr-client: '1.0.0-alpha2-final' in my project. Angular-cli releases link: https://github.com/angular/angular-cli/releases |
When creating a vanilla angular-cli project and adding signalr-client (currently alpha1 26666) the app crashes when trying to reference any members exposed from the import statement.
This occurs at the point the members are actually referenced: the act of including the members in the code file doesn't trigger the error - I'm assuming that is because of lazy loading the resources when they are actually used, but that's of course outside my area.
This occurs both in dev and prod builds. In my case it originally broke in a angular-cli based .net core project, however I was easily able to reproduce the same outcome in a vanilla angular-cli project.
Note I am using yarn, however that shouldn't make any difference
To reproduce the issue, I did the following:
Create a new angular-cli project
ng new test-signalr-client
[I saved the initial commit in the auto-created git repo]
I added the signalr-client - to do this in yarn I followed the following steps :-
a.
yarn config get registry
(so I can revert back afterwards)b.
yarn config set registry https://dotnet.myget.org/f/aspnetcore-ci-dev/npm/
c.
yarn add signalr-client
d.
yarn config set registry https://registry.yarnpkg.com
(to revert back to standard yarn registry)[Saved commit]
Amended the app.component.cs as follows:-
ng serve
or ```ng serve --prod``Open dev tools in the browser, and view the console errors.
Although this is an alpha build, it goes without saying that there's no point even trying to integrate this new "style" of signalr into a .net core/angular-cli project until this is resolved
The text was updated successfully, but these errors were encountered: