Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
463 views
in Technique[技术] by (71.8m points)

node.js - Running tsc from the Windows command line

npm is installed and is actively being used from IntelliJ IDEA 15

My goal is to generate typings for my TypeScript source code in IntelliJ, but I want to learn using the Windows command line, so I can explicitly specify the command line options to tinker to understand what each option does. I am confused by the various tidbits related to setting this up and using it that I've found by Googling... I'm sure that I'm missing something very basic that those who blog or answer questions assume as common knowledge...

Here's what I've attempted and what I'm seeing...

Step 1: install typescript:

npm install -g typescript

This results in the following file/directory structure being installed on my system:

C:Users{my user id}AppDataRoaming
pm
ode_modulesypescript
|---bin
|   |--- tsc
|   |--- tscserver
|---lib
|   |--- lib.core.d.ts
|   |--- ...
|   |--- typescriptServices.js
|--- .npmignore
|--- ...
|--- ThirdPartyNoticeText.txt

Step 2: naively try to run tsc directly from the Windows command line:

The examples that I've found by Googling take the form:

Compile a single file:

tsc app.ts

above example is from http://www.primordialcode.com/blog/post/typescript-command-line-compiler

This does not work as shown because:

  1. The install directory of tsc is not on the Windows Path C:Users{my user id}AppDataRoaming pm ode_modulesypescriptin, obviously this is easily remedied or worked around by changing the Window PATH environmental variable and/or fully qualifying the path to the tsc file when entering the command to execute.

  2. More significantly the tsc file is not a Windows executable... the #! Unix script (shebang) being a dead giveaway.

Inspecting the tsc file:

#!/usr/bin/env node
require('../lib/tsc.js')

Step 3: try to run tsc from the node command prompt:

C:>node

> tsc

ReferenceError: tsc is not defined
at repl:1:1
at REPLServer.defaultEval (repl.js:252:27)
at bound (domain.js:287:14)
at REPLServer.runBound [as eval] (domain.js:300:12)
at REPLServer.<anonymous> (repl.js:417:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
at REPLServer.Interface._line (readline.js:549:8)
at REPLServer.Interface._ttyWrite (readline.js:826:14)

^C

OK... let's specify the full path to the tsc script:

C:>node

> C:Users{my user id}AppDataRoaming pm ode_modulesypescriptinsc

...

literally the only output is ... when specifying the full path to the tsc script... I guess that it wants parameters... but hitting the tab key reveals a list of what seem to be node commands (not tsc commands)... so I've no idea what's going on here...

Now I'm stuck

What environment do I need to install/configure/use to invoke tsc (as illustrated by: http://www.primordialcode.com/blog/post/typescript-command-line-compiler)?

and/or

Is there a tutorial or site that would help me go from a clean Windows system to being able to use the TypeScript compiler from the command line to generate typings for my TypeScript source files?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should not add TypeScript's bin folder directly to the Windows PATH. As you noticed, the files in that bin folder are not directly executable from the command line.

Instead, npm creates a .cmd script for every configured executable in a globally installed package and puts it in:

%APPDATA%
pm

Try updating your PATH to include this folder, re-open your command line and try running tsc again.

Side note: the Node.js installer for Windows by default adds Node and NPM to your Windows path. If you have installed Node.js normally, this should have worked just fine. Anything special about how you have your Node set up?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...