Despite the presence of TypeScript installation, both VS Code and Windows fail to acknowledge its existence

Recently, I've been immersed in a VS Code project that predominantly uses TypeScript.

After committing the project to GitHub and downloading it onto my usual machine for TypeScript development, I encountered an issue when trying to build the project in VS Code:

tsc : The term 'tsc' is not recognized as the name of a cmdlet, function, script file, 
or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:1
+ tsc
+ ~~~
+ CategoryInfo          : ObjectNotFound: (tsc:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Upon researching similar issues on StackOverflow, I attempted several solutions:

  1. Installed TypeScript using npm with the command npm install -g typescript. The installation showed no errors, indicating that it was successful (confirmed later in Step 3).
  2. Checked my environmental variables to ensure there were no unusual paths pointing to the tsc compiler. None were found.
  3. Ran the command npm list -g to confirm that TypeScript was indeed installed globally (which it was).
  4. As a precautionary measure, ran the command from the path identified in Step 3, resembling
    C:\Users\MyUserName\AppData\Roaming\npm\tsc
    , and it executed successfully.
  5. Considering the results of the previous check, I opened a fresh command prompt and attempted running tsc -v, but the OS did not recognize the command.
  6. Executed the command
    setx path "%paths%:C:\MyUserName\AppData\Roaming\npm"
    to add the npm global directory to the system environment paths variable. Despite this modification, restarting the command line and attempting an unqualified tsc command yielded no results.

It seems that simply running npm install -g typescript does not effectively install TypeScript in a manner that the system acknowledges on a global scale, despite using the -g/"global" flag. Clearly, something crucial eludes me. Can anyone pinpoint what exactly I'm missing?

Answer №1

Following the installation of node.js 10.13.0 LTS, I noticed that after restarting both my command prompt and VS Code, tsc was able to run successfully.

Therefore, it is important to keep node updated in order to avoid any unexpected issues with tsc!

Answer №2

For checking the version of Typescript, you can try running npx tsc -v. To execute a .ts file, use the command npx tsc filename.ts. If everything is set up correctly, it should work without any issues.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to access MySQL after installation due to error code 1045 (28000) stating: "Access denied for user 'mike'@'localhost' (using password: YES)"

After setting up mysql on my Mac with Mountain Lion, I ran into an issue while trying to log in using the given command: mysql -u mike -p The error message that popped up was: ERROR 1045 (28000): Access denied for user 'mike'@'localhost&a ...

What is the process of TypeScript module resolution within the Play framework?

In my Play project, I am interested in incorporating Angular 2 with TypeScript. Utilizing the sbt-typescript plugin and the angular2 WebJAR, I have encountered a situation where Play places the extracted WebJAR in target/web/public/main/lib/angular2. Ideal ...

Getting an Error Message When Trying to Run "npm start" Command in Gitbash

I've been working through the "Lynda's Learning Angular 2" course and I'm currently stuck on the third video. I followed all the instructions, created a "learnangular" folder, installed dependencies with the "npm install" command, checked ou ...

Troubleshooting issues with debugging in Visual Studio Code when working with Node.js

Recently, I've started using Visual Studio Code to debug a Node application. After generating the launch.json file, here is the configuration: "configurations": [ { "type": "node", "request": "launch", "nam ...

What is the method to cancel an Observable subscription without having a reference to the object of type "Subscription"?

If I were to subscribe to an Observable without an object of type "Subscription," how can I properly unsubscribe from it? For instance, if my code looks something like this: this.subscription = bla ... I know I can easily unsubscribe using the following ...

A function in Typescript that returns an array of strings

I am experiencing an issue where my console statement is not displaying the length of the string array. Oddly enough, when I print 'list' within the for loop, it does show data. public getText = (items: any) => { let list: string[] = []; ...

Implementing Microdata with React and Typescript: A Comprehensive Guide

Whenever I include itemscope itemtype="http://schema.org/Product" in h1, an error pops up: The type '{ children: string; itemscope: true; itemtype: string; }' is not compatible with the type 'DetailedHTMLProps<HTMLAttributes<HTMLH ...

Maintaining search filters across pages in Angular 2 using URL parameters

I am attempting to store certain filters in the URL for my application, so that they can be reapplied when the page is reloaded. I am encountering challenges with Dates (using moment), nullable properties, and special characters (/). When I pass values to ...

Revising Global Variables and States in React

Recently delving into React and tackling a project. I find myself needing to manage a counter as a global variable and modify its value within a component. I initialized this counter using the useState hook as const [currentMaxRow, setRow] = useState(3) ...

What is preventing the command "npm run <command>" from functioning properly?

npm run is failing to work on any project, preventing me from installing packages with post-installed scripts. The error message displays details about the npm CLI and paths involved in running tests. 0 info it worked if it ends with ok 1 verbose cli ... ...

Having to reinstall node modules is a repetitive task that must be done after each build of an Angular

Formulating this question has been quite challenging for me. I really hope it is clear. Despite my extensive searches, both on this platform and beyond, I have not been able to find any reference to the behavior I am experiencing. For the past few ...

Angular 6 and the intricacies of nested ternary conditions

I need help with a ternary condition in an HTML template file: <div *ngFor="let $m of $layer.child; let $childIndex=index" [Latitude]="$m.latitude" [Longitude]="$m.longitude" [IconInfo]="$childIndex== 0 ? _iconInfo1:$c ...

Tips for typing the following object/type in TypeScript

I need help with typing a user state in my application. I have the following: a user type which includes id, email, firstName, lastName, and verified fields. export type User = { id: string | null; email: string | null; firstName: string | null; l ...

SlidingPane header in React disappearing behind Nav bar

Here is the code snippet from my App.js file: export class App extends React.Component { render() { return ( <BrowserRouter> <NavigationBar /> <Routes /> </BrowserRout ...

The type 'JSX.Element' cannot be assigned to type 'Element'

After updating my dependencies, I encountered more build errors than before. While attempting to resolve them, one error remains persistent. The code snippet causing issues: children: Element[]; Element: JSX.Element; I attempted to address the problem ...

Mismatched return type of function overloading in TypeScript when no function arguments are provided

I have a function that returns objects with different values based on specific conditions, without any arguments passed to it. Although I have written two overloads specifying different return types, when using the function and attempting to destructure v ...

Intellisense in VS Code is failing to work properly in a TypeScript project built with Next.js and using Jest and Cypress. However, despite this issue,

I'm in the process of setting up a brand new repository to kick off a fresh project using Next.js with TypeScript. I've integrated Jest and Cypress successfully, as all my tests are passing without any issues. However, my VSCode is still flagging ...

The state array is rejecting the value from the other array, resulting in null data being returned

I am currently attempting to extract image URLs from an HTML file input in order to send them to the backend and upload them to Cloudinary. However, I am facing an issue where despite having the imagesArr populated with images, setting the images state is ...

Tips for resolving the issue of 'undefined' object in TypeScript with Angular 14

Previously, the below code worked fine in Angular for me. However, I am now encountering an error in Angular 14 stating Object is possibly undefined: this.progress = Math.round(100 * event.loaded / event.total); The issue seems to be with the event.total ...

Implement dynamic typing in the sort function to restrict it to only accept number properties

I need help creating a pipe that can sort an array of objects based on a specified property. While I have managed to make it work, I am encountering a type error in my code. Here is the snippet: export const sortByProperty = <T>(a: T, b: T, property: ...