'tsc command not found' in compiling typescript

后端 未结 15 881
耶瑟儿~
耶瑟儿~ 2020-12-05 02:02

I want to install typescript, so I used the following command:

npm install -g typescript 

and test tsc --version, but it just

相关标签:
15条回答
  • 2020-12-05 02:14

    Non-admin solution

    I do not have admin privileges since this machine was issued by my job.

    • get path of where node modules are being installed and copy to clipboard
      • npm config get prefix | clip
      • don't have clip? just copy output from npm config get prefix
    • add copied path to environment variables
      • my preferred method (Windows)
      • (Ctrl + R), paste rundll32 sysdm.cpl,EditEnvironmentVariables
      • under User Variables, double-click on Path > New > Paste copied path
    0 讨论(0)
  • 2020-12-05 02:16

    This works perfectly on Mac. Tested on macOS High Sierra

    sudo npm install -g concurrently
    sudo npm install -g lite-server
    sudo npm install -g typescript
    tsc --init
    

    This generates the tsconfig.json file.

    0 讨论(0)
  • 2020-12-05 02:18

    A few tips in order

    • restart the terminal
    • restart the machine
    • reinstall nodejs + then run npm install typescript -g

    If it still doesn't work run npm config get prefix to see where npm install -g is putting files (append bin to the output) and make sure that they are in the path (the node js setup does this. Maybe you forgot to tick that option).

    0 讨论(0)
  • 2020-12-05 02:22

    If your TSC command is not found in MacOS after proper installation of TypeScript (using the following command: $ sudo npm install -g typescript, then ensure Node /bin path is added to the PATH variable in .bash_profile.

    Open .bash_profile using terminal: $ open ~/.bash_profile;

    Edit/Verify bash profile to include the following line (using your favorite text editor):

    export PATH="$PATH:"/usr/local/lib/node_modules/node/bin"";
    

    Load the latest bash profile using terminal: source ~/.bash_profile;

    Lastly, try the command: $ tsc --version.

    0 讨论(0)
  • 2020-12-05 02:26

    For windows:

    Add the path by using command as below in command prompt:
    path=%path%;C:\Users\\npm

    As in my case, the above path was not registered for command.

    %userprofile% in run windows, will give you path to C:\users\

    0 讨论(0)
  • 2020-12-05 02:28

    I had to do this:

    npx tsc app.ts
    
    0 讨论(0)
提交回复
热议问题