1

I am using TypeScript Node NPM module to compile my .ts files in my project.

The simple case

As for documentation (that is condensed in the NPM page the link I reported above leads to), when compiling a simple file, I just need to:

node node_modules/typescript/bin/tsc.js main.ts

The not so simple case

However, I need to pass parameters to the compiler, so I do this:

node node_modules/typescript/bin/tsc.js main.ts --module commonjs --out out/main.js

But it looks like the --module commonjs --out out/main.js part is not considered and gets lost.

How to successfully pass parameters to tsc.js invoked through 'node'? Thanks

2 Answers 2

3

it looks like the --module commonjs --out out/main.js part is not considered and gets lost.

Not true. It works fine. Most probably the thing you are experiencing:

Do not use --module and --out together

Basically don't use --out. For your use case (to redirect output to a different directory) use --outDir.

Personally, I dislike out for beginners : https://github.com/TypeStrong/atom-typescript/blob/master/docs/out.md

Sign up to request clarification or add additional context in comments.

4 Comments

Wow, I did not know about such terrible side effects of using --out!
What if I use --out in tsconfig.json? I mean --out is still something we need, otherwise I'd need to create manually a dependency tree to get the correct order of concatenation for my files and that is simply something crazy for big projects. Thanks to --out all reference declarations will guide the compiler to generate a final correct .js file!
otherwise I'd need to create manually a dependency tree to get the correct order of concatenation for my files and that is simply something crazy for big projects. No. External tools will do that for you. If you are using node you don't need to merge into a single file. If you are using browser tools like webpack or browserify will do this for you
I guess there is a lot I need to learn about those tools. Thanks for letting me know: learning time i guess :)
0

By installing typescript with

npm install -g typescript 

you should get also the command line compiler (tsc) that you can invoke like you were doing

tsc main.ts --module commonjs -out out/main.js

what you were trying to execute is probably not taking the arguments at all (did you build typescript from source?), all compilation should be done with tsc. Even the tutorial suggests doing so, and you can find more examples in the handbook.

5 Comments

I know this, but my point is to use the provided version of TypeScript. The point is including TypeScript in the project and not having the user installing it with the version support. Thus once the user downloads the project, he has everything he needs, no need to install more stuff...
@Andry how do you plan to distribute the project? Normally you would just add dependencies to that and call npm install, then the user would have tsc since typescript should be a dependency, or is the situation different?
By installing TypeScript module locally in the project folder via npm install typescript (no -g option) I install the module with the version I intend without the need for the user to install it. So the point is: download the project folder and run the script in the folder which will call all necessary things and build stuff for you. The user must not install anything as all resources are provided in the project.
@Andry you could also do this by using typescript-compiler and build all your .ts files from a javascript called with node, you can give it the same parameters as tsc.
I looked at it, I do not like since it is not a module from Microsoft, thus not official. I know I am being picky, however, is it possible that I cannot provide parameters to the TypeScript module? There must be a way...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.