3
Vote

the "Combine Javascript output into file" option does not work.

description

The "Combine Javascript output into file" option does not work for me. It does not take the server.js file so I have the classes I defined in a subfolder, but not the initialisation code that is in server.js.

Is there a workaround ?

comments

bokan wrote Aug 17, 2014 at 11:07 PM

In fact it works until there is a
import http = require('http');

line in the main file. I tried command line with tsc.exe it give the same result... so it's not a NTVS problem.

(if someone can point me to an explanation of the problem I'll be gratefull)

pminaev wrote Aug 18, 2014 at 3:37 AM

I would expect that this is because Node.js module system wants to have modules in separate files, so the "combine in one file" TS mode doesn't make much sense. Can you tell more about your scenario - i.e. why do you want to use this option? Perhaps there's a better way to achieve this with Node.

nabog wrote Aug 18, 2014 at 8:05 AM

@pminaev is right. "Combine Javascript output into file" will not currently work for external modules.

bokan wrote Aug 18, 2014 at 8:10 AM

I want to instanciate my classes with the syntax "var instance=new MyClass();" wich is much more convenient in my own opinion.

To do this, I usually combine all files in one. Bur with Nodejs, as soon as there is a "import http = require('http');" line, the code of server.ts is not combined.

Everything works great if I combine files manually.

bokan wrote Aug 18, 2014 at 8:16 AM

I just replaced
import http = require('http');

by
var http = require('http');

and it works as expected.

Thank you for your attention.

I do not create modules in my project.

bokan wrote Aug 18, 2014 at 8:32 AM

Maybe import should be replaced by var in the template project ?
Why using import there if var works ?

nabog wrote Aug 19, 2014 at 8:53 AM

When writing var http one is writing JavaScript and not TypeScript. There is some documentation on the github site.

Alphapage wrote Aug 22, 2014 at 10:32 PM

Why do we want to combine Javascript output into one file for typeScript development ?

The answer is very simple to me:
avoid all .js and .js.map files to polluate the njsproj !

As soon as I discovered this option provided by tsc, my project was clean, easy to organize even in Windows Explorer and share.

This feature is necessary for me and works with all other TypeScript projects in Visual Studio, so why not for NodejsTools ?
But this is just my opinion and I hope you will take in consideration.

pminaev wrote Aug 23, 2014 at 12:15 AM

Can you clarify "avoid all .js and .js.map files to polluate the njsproj"? The normal workflow for these is to not have them in your .njsproj file. You can still get to them with "Show All Files", and if you write mixed JS/TS code, the analyzer will still pick them up; and web site publish will package them up regardless, too. But otherwise, the expectation is to treat them purely as build artifacts, just like "obj" and "bin" folders.

Alphapage wrote Aug 23, 2014 at 8:12 AM

"avoid all .js and .js.map files to polluate the Nodejs project folders" for clarification and I never mentioned .njsproj file. Sorry for my bad explaination.

I always turn "Show All Files" on in all my projects to keep control over hidden files which is probably my problem. In my point of view, example1.js and example1.js.map files attached to example1.ts (...) for a njsproj project could be considered as example1.dll and example1.pdb files attached to example1.cs (...) for a csproj project. I know that's a very bad example.

If you want to share quickly from one njsproj project to another one, 20 classes from 20 .ts files, that's easier to combine js and get 1 .js .js.map .d.ts file instead of searching those 20 .js .js.map .ts files.

"This feature is necessary for me and works with all other TypeScript projects in Visual Studio, so why not for NodejsTools ?"

bokan wrote Aug 23, 2014 at 8:21 AM

@pminaev

Can you please explain or point me to a documentation that explain the workflow to :
  • have classes in separates .ts files
  • instanciate classes with the syntax "var instance=new MyClass();" (with references) an not "import http=require('http'); server=new http.server(...."
  • allow to use modules for third party libraries

bokan wrote Aug 23, 2014 at 8:28 AM

I meant allow to use external modules (for nodejs).

mousetraps wrote Jul 15, 2015 at 9:08 PM

Hey all, this feature is now implemented and available in the latest dev build hosted at our new home on GitHub!

mousetraps wrote Jul 15, 2015 at 9:10 PM

To clarify, we've enabled debugging when using this option. didn't read this issue carefully enough before I posted :)