Saturday, December 5, 2015

Typescript Turmoil in VS Code!

Recently, at work, we've switched from ASP.NET MVC development to AngularJS / Nodejs. It's been a bit of a struggle, and a decision that was outside my purview. Nevertheless, learning something new is always good, and it seems that MS is joining the MEAN camp part way by supporting Node, Angular, and Express with their suite of Visual Studio products. I believe you can also have a Mongo instance in Azure, but don't quote me on that - could be a senior moment ....

Unfortunately, with great complexity, comes great confusion...

At first, I simply added the Nodejs tools to Visual Studio 2013. That seemed to work ok, but at work we're using WebStorm. Visual Studio with Node simply seems to make projects and applications in a different enough way that it wasn't helping me with work. So I installed VS Code. I tried for weeks (part time at home on the weekends while managing family obligations) to get VS Code to do something as simple as build a one file .ts application. Finally, after banging my head against the wall (figuratively), I have gotten it to work. Hopefully, I can save some people some bruising ...

There were two salient factors that made my life so miserable for so long.

  • If you have installed Node Tools for Visual Studio, and then subsequently run (as suggested) "npm install typescript -g" to install typescript for VS Code, you now have TWO (count them, two!) potentially different versions of the typescript compiler in TWO different places. 
  • Running "npm install typescript -g" puts typescript in a location that is not reflected in your PATH system variable. Yet all of the "examples" of how to configure your tasks.json file seem to assume that the npm-installed typescript compiler will be found automagically. Oddly enough, this did not happen for me.

So the corrective actions that I took to get things to work are actually quite simple.
  • Remove the path to the Node Tools installed version of typescript from your PATH system variable. If you don't know how to do that instructions are here.
  • In a command or powershell window enter "npm list -g". This will show you all the globally installed npm packages. Here's what mine looks like:
c:\>npm list -g
C:\Users\Steven Archibald\AppData\Roaming\npm
└── typescript@1.7.3

What's important is that first line of the response:
"C:\Users\Steven Archibald\AppData\Roaming\npm"
Copy that from your machine and save it in a text file for the moment.

When you create your first tasks.json file in VS Code, it will look like this:
// A task runner that calls the Typescript compiler (tsc) and
// Compiles a HelloWorld.ts program
"version": "0.1.0",

// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
"command": "tsc",

// The command is a shell script
"isShellCommand": true,

The line, "command" : "tsc", is why my .ts files were not being compiled. The root of the problem is,  VS Code is just going to look in your local directory (apparently) to find the typescript compiler. It won't find it there - you installed it globally, remember? And you don't have a path statement to point to where it really is.

So, you could add the "...\npm" path to your PATH system variable (I haven't tried that yet), or you could change your tasks.json file to have:
"command": "C:\\Users\\Steven Archibald\\AppData\\Roaming\\npm\\tsc",
It now works as expected!
Note that your path will be different based on what your "npm list -g" returns, and that the "\\" are required to escape the "\" character.

Hope this helps save people some time, and Happy Typescripting!

Sunday, August 23, 2015

More Crap From Microsoft?

Sigh ...

It just keeps getting worse.

First, let me preface this with the disclosure that I have been developing on Windows (Desktop and Web) exclusively since 1994. For the most part, I think Microsoft's Developer Tools are the best available. While I will be commenting about Visual Studio Code in a subsequent post, this is about something else. I also happen to like the Windows Desktop interface (have to clarify that now since there is a "tablet" interface as well). I find it highly intuitive, and better than the Apple desktop interface. I even prefer to use IE over the other browsers. I do use the other browsers, I've just like IE better than the others.

Recently, I upgraded from Windows 7 to Windows 10. Along with the new OS came the latest instantiation of IE, Microsoft Edge. I do like the cleaner interface.

But I detest the fact that I cannot set my New Tab options to open with my home page. I use as my homepage. I like the daily pictures, I've signed up for Bing rewards, and I find the Bing search engine to be just as useful as the Google search engine. But with Edge, I can no longer set my new tab properties to open with the same address as my home page. I can't tell you in words (or Word) how much that pisses me off.

I'm assuming it's because they want to force you to look at their "top sites" for marketing, advertising, whatever, dumb-ass revenue gathering reason.

It's counter productive.

I hated the recent versions of Firefox and Google and refuse to use Opera for the same reason - on my computer, I don't like being forced to do things the way someone else thinks I should.

It's a PERSONAL computer. It's MY computer. I'll use your software if you let me use MY computer the way I want to use my computer.

At this point, Microsoft has given me no reason to prefer Edge over Firefox or Chrome. Great marketing move, Microsoft - make sure there's no real UX experience between yourself and the other guys. You don't keep or gain marketing share if you aren't any different from the other guys. And speedier rendering on the order of microseconds is not a sufficient discriminator - everyone always makes their browser a little bit faster with every round.

It's back to IE 11 for me...