Servicestack Client not working after minification


Servicestack javascript clients works fine. But after minifying and bundling whole application it is unable to request the url. It is requesting url like http://localhost/json/reply/e instead of POCO name.

I am mostly missing something. But couldn’t figure it out. It would be great if someone can point me into right direction.


We’re going to need a lot more info on exactly what the issue is and what you’re referring to. What did you minify, how? and what code is no longer working?

Hi @mythz

Thanks for quick reply. I’m using service stack client library with Fable-Elmish .

It is working great in dev mode. Without any issues. Means I don’t have to provide URL. Library is figuring out.

But when I minified using web pack. It just request alphabet. As shown in above question. My best guess it, it is minifying javascript object names (F# types ) and that is breaking the client. I’m sure that if I give URL too it will work (haven’t tried though).
But currently whole no URL option broke for me in minified code.

Fable-ElMish: it is wrapper around react and redux to provide elm architecture in F#. Fable transpile to ES6 and then bable transpile to current java script. And all magic happens using web pack.

This description isn’t helpful, please provide the exact source code that’s causing the issue, including the libraries you’re using as well as the DTOs. i.e. provide all relevant info in order to be able to reproduce the issue.

You should be able to use minified TypeScript Service Client generated DTOs, but if you’re using regular JavaScript classes you wont be able to minify them because the client needs the type name in order to construct the URL to query the Service and if you minify plain JS DTOs the Request DTO name is lost.

Hi @mythz

Sure. Will share the details by tomorrow.

Thanks replying again.


Hi, @mythz

Here is the project to reproduce the issue. You can follow read me to run it in dev mode.

Then for Todo in dev mode URL coming as http://sometodourl/json/reply/ToDoByUser . Now if you run command dotnet fable npm-run build it will create minified javascript for whole project. Currently it is checked in into public folder.

So, you can run any local server for public folder (I am using node http-server). It will run everything but while hitting server it is coming as http://sometodourl/json/reply/e .

PS: sometodourl I put as dummy url. As I am just testing for generated url while hitting network.


PS: This was the demo I was talking about a little back. Years back in early days of Servicestack you introduce the concept of message passing for communication with server for dot net. Now, every latest java-script architecture like Elm, Fable-Elmish is using it. They force server framework to think in message passing and as servicestack is already having concept it; it fits right into it. Even here I just copy -pasted DTOs and they are used directly as model. I don’t have to translate it anyway. And thanks for seeing the future way back in past. :wink:

ok so it looks like you’re trying to use F# DTOs in your Fable project than compile that to JS.

But you can’t minify the F# DTOs because they won’t preserve the Type Name which is needed in order to construct the url so your options are:

  • Extract the F# DTOs into separate .js file which you configure to not get minified
  • Use TypeScript DTOs (transpiled to js) instead which are safe to Minify
  • Add a member this.getTypeName() = "TheDtoName" to your F# DTOs which the ServiceStack JsonServiceClient will use instead.

Hey, @mythz

Last option of adding this.getTypeName() worked.

Have a look. this line actually did the magic. Thanks man…

I’ve just ran into this issue after getting our minified production build for React. Our project is JS / JSX, and we use the TypeScript DTO’s transpiled to js and minified, but receive all the same errors. @mythz was there something else we have to do to make this work?

The generated TypeScript DTOs should survive minimisation, please provide a stand alone repro of what doesn’t work.

For anyone stumbling upon this, your dtos MUST inherit from some type of IReturn (IReturnVoid, IReturn<>, QueryDb<>, etc…).

Otherwise the getTypeName() isn’t generated in your dtos.ts.

1 Like

Also most of the typed Service Client APIs (in all languages) require it.

1 Like

Yeah ServiceStack made me a little lazy and I was enjoying some of the type-freedom with returning objects :rofl:. I learned my lesson though.

1 Like