Couldn't Get Typescript Support While Upgrading to Babylonjs v5

Hello! I just downloaded VS Code and used it for the first time yesterday to upgrade to Babylonjs v5.9 using the Getting Started steps in the docs. Everything went smoothly until I got to the TypeScript support part and typed “tsc --init.” I got an error about “tsc” not being recognized–and the tsconfig.json file wasn’t created. Searching the INet led me to the possibility of installing TypeScript globally, with: “npm install -g typescript” But that brought up the error: “tsc : File C:\Users\Ken\AppData\Roaming\npm\tsc.ps1 cannot be loaded because running scripts is disabled on this system.”

That led me to a microsoft doc page called “about_Execution_Policies,” which led me to the discovery that my Powershell system’s Execution Policy is “Restricted,” which doesn’t allow for the running of code needed to install TypeScript. I’m not sure if I’m using the right language to describe that, since I’ve never encountered it before. The article went on to say that I can switch from Restricted to something like Bypass, but there are warnings about opening up my computer to malevolent code.

I thought, if I can’t install TypeScript globally, maybe I can do it locally, just for the project I’m working on. Sure enough, I discovered “npm install --save-dev typescript,” which seemed to work, since I got the message: “up to date, audited 362 packages in 2s” and no errors. When I tried “tsc --init” again, however, I still got error messages about the restricted status of my system.

The other option that I thought might work is to use a TypeScript extension with VS Code, only to discover that there’s a multitude of TypeScript extensions that do different things.

Further searches in VS Code forums, YouTube and the Babylonjs forum didn’t get me any closer to a solution. I was wondering if anyone else here has encountered this problem and found a solution? I might have to use another editor, but VS Code is highly recommended, and it seems to work very well…

I went to the TypeScript website, too, and found the same npm installation instructions, both global and local, that I already tried. :frowning: Now I just had the thought that–since the local install seemed to work–maybe there’s another way to create the tsconfig.json file besides “tsc --init”? Yesterday I tried to manually create the file in VS Code and then fill it with the code indicated by the Getting Start doc, but that didn’t seem to work either.

cc @RaananW

1 Like

Hey @terransage,

tsconfig.json is a very simple file to create yourself. in fact, I don’t think I have ever used tsc --init.
The file is fully documented on the typescript website, but in general, all you need is an input and an output, and then start playing with changing the default values with what you need for your project.

If you manage to install typescript locally as a npm dependency, that’s perfect. make sure you use npx before running tsc cmmands, and you will always use the local typescript version. i.e. npx tsc --init would probably be the command you need to run to use the local typescript version’s init command.

We have tried to simplify that way you work with typescript, so we provide an explanation to install typescript globally, beause then tsc will simply work all over. but having a local version of typescript is actually the safer way on the long run, because then you can get different typescript versions on different projecs.

I hope it all made sense :-). I will be happy to help further if there are any other issues

1 Like

Thanks, Sebavan and Raanan, for the quick response! I’m itching to try out your suggestions, but I can’t get back to my computer until this evening. I was able to download everything else and create all of the other files, but just got stuck on the TypeScript issue. The Babylon community is great! :cowboy_hat_face:

2 Likes

Three things did it for me: 1) deleting ALL of my files (because I had fiddled around with them too much yesterday while trying to find a solution), 2) starting the whole setup process from scratch, and 3) using the “npx tsc --init” command to create the tsconfig.json file (instead of tsc --init). Not a single error appeared after any command, and running localhost produced a beautiful sphere. I was as happy to see that sphere as I was to see my first cube in Unity many years ago. :smiling_face_with_tear: Thanks again for your help!

2 Likes