Aspnetcore.docs: Utils.ts:12 Uncaught Error: The 'protocol' argument is required.

Created on 23 May 2018  Â·  24Comments  Â·  Source: dotnet/AspNetCore.Docs

I received the above error due to an error in chat.js.

Following the example documented at https://www.npmjs.com/package/@aspnet/signalr, I initialised the connection in chat.js as follows:

const connection = new signalR.HubConnectionBuilder()
    .withUrl("/chathub")
    .build();

Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Source - Docs.ms

All 24 comments

Just stumbled over the same Problem...
Looks like it's something from the last update to the js client.
If i revert the signalr.js to v1.0.0-preview2-final it works.

but there is no HubConnectionBuilder so my connection setup looks like this:

var connection = new signalR.HubConnection("/Hub");

This error is usually caused by not having the same version of client and server. I'm guessing you're using preview2 of the Server and trying rc1 of the client.

I'm using the rc1 server:

<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.0-rc1-final" />

The same problem, using: client - 1.0.0-rc1-update1, server - 1.0.0-rc1-final

@photomoose @aivism Is this error happening with the sample located here https://github.com/aspnet/Docs/tree/master/aspnetcore/signalr/get-started/sample?
Try the code here
https://github.com/aspnet/Docs/blob/master/aspnetcore/signalr/get-started/sample/wwwroot/js/chat.js

That error normally happens as Brennan stated - when there is a version mismatch, and the docs have been recently updated.

const connection = new signalR.HubConnection(
"/chathub",
{ logger: signalR.LogLevel.Information });

Same error. I'm using Visual Studio Code on Ubuntu 18.04. How do I know which version of server I'm using when the only entry in csproj is the new versionless ?. For the npm package, npm i @aspnet/signalr gets "^1.0.0-rc1-update1" today.

@rachelappel The sample works fine, but note that the client version of signalr.js is not installed as an npm package in the sample.

Comparing my solution with the sample:

  • Both samples are using Microsoft.AspNetCore.SignalR (1.0.0-rc1-final) on the server

  • My solution is using the @aspnet/signalr (1.0.0-rc1-update) npm package for the client which has a HubConnection prototype defined as:

function HubConnection(connection, logger, protocol)
  • The sample has an included signalr.js implementation (not from npm) with a HubConnection prototype defined as:
function HubConnection(urlOrConnection, options)

@Languafe The .csproj doesn't show the version for the signalr.js file that you get from npm. There is no version in the file itself.

@photomoose It looks like there still might be a version incompatibility. @anurse can you confirm?
The signalr.js is most definitely from npm though.

The subject is about Utils.ts - which is not part of the sample. Is that where the error is happening?

Same problem here after following the tutorial.

The tutorial says to run npm install @aspnet/signalr and to copy the file signalr.js to lib folder. I don't understand what @photomoose means about "The sample has an included signalr.js implementation (not from npm)".

@rachelappel exactly, so how am I to know if there is a mismatch between client and server in my project when all I have is the package.json?

Oh, @Languafe I fixed this by doing what I guess @photomoose also did - I got the JS file from: https://github.com/aspnet/Docs/blob/master/aspnetcore/signalr/get-started/sample/wwwroot/lib/signalr/signalr.js and replaced the text of the one the tutorial tells you to get from npm.

It seems there is a mismatch between the version of the client JS library hosted on npm and the one needed by the JS code in this example.

The problem is that the code example in the documentation at https://docs.microsoft.com/en-us/aspnet/core/signalr/get-started?view=aspnetcore-2.1&tabs=visual-studio is incorrect.

The documentation says to install the signalr client from npm using npm install @aspnet/signalr - and then create the hub connection in chat.js with the following code:

const connection = new signalR.HubConnection(
    "/chathub",
    { logger: signalR.LogLevel.Information });

This code is incorrect for the current npm version and the documentation needs updating. This is how the npm version expects a HubConnection to be created: https://github.com/aspnet/SignalR/blob/dev/clients/ts/signalr/src/HubConnection.ts#L62

@Languafe What I mean about "the sample has an included signalr.js implementation" was in reference to @rachelappel's comment earlier, where she asked me to see if it works in the sample project in Github - which it did, because it signalr.js was included in the project, and was not the latest from npm.

@rachelappel

The subject is about Utils.ts - which is not part of the sample. Is that where the error is happening?

No, that's the error you get in the browser console window - it has nothing to do with Utils.ts. The error is in chat.js - all that is wrong is the documentation - the way in which HubConnection is instantiated in Javascript using the latest npm package is different from what the documentation states.

@photomoose The sample is using 1.0.0-rc1-final version, not the latest from npm, for both server and client. If using Visual Studio 15.7 as stated in the doc, with matching rc1-final version on both server and client, the sample works.

You can check https://www.npmjs.com/package/@aspnet/signalr and click on the Versions tab on the right for the correct client version to match the server. The doc is the 1.0.0-rc1-final version and was specifically written for 1.0.0-rc1-final until the RTM is released. I can't say when the release date will be, other than "soon".

This code, which is what was opened in this issue, will not work in the JS client, and will also throw transport errors.
const connection = new signalR.HubConnectionBuilder()
.withUrl("/chathub")
.build();

@Languafe Check https://www.npmjs.com/package/@aspnet/signalr and click on the Versions tab on the right for the correct client version to match the server.

@rachelappel but that means this line in the docs: npm install @aspnet/signalr is wrong. We ran that and it got the _latest_ version of signalr from npm - which is this 1.0.0-rc1-update1. Not 1.0.0-rc1-final which you say works.

The code in 1.0.0-rc1-update1 is identical to 1.0.0-rc1-final. The only change is a README file update.

Oh. Then the thlot pickens. And that suggests the statement click on the Versions tab on the right for the correct client version to match the server. The doc is the 1.0.0-rc1-final version is incorrect?

@IanIsFluent As Brennan said "This error is usually caused by not having the same version of client and server.", because there are some versions that don't play nice together. I find it is easiest for readers and for development to match the versions. It keeps the doc simple to follow, especially for a Getting Started doc. Rather than have readers slog through a table of which versions work with which. One example, "preview2 of the Server and trying rc1 of the client." as previously mentioned, doesn't work together. So yes, technically, it's incorrect for the scenario you just mentioned, but correct for others as some versions don't work together, keeping the goal to be the easiest route for readers.

"but that means this line in the docs: npm install @aspnet/signalr is wrong." This should be updated to note the rc1final version.

All of this gets cleaned up in the upcoming RTM release too, where we will have a stronger cross-version compatibility guarantee.

@rachelappel this doc isn't updated and is completely broken for Rc1. Looks like we didn't update it as part of the Rc1 docs.

This is resolved now

Was this page helpful?
0 / 5 - 0 ratings