Typescript: Why not supported outFile parameter on CommonJS module system since TypeScript 1.8

Created on 26 Feb 2016  ·  26Comments  ·  Source: microsoft/TypeScript

I was unable to use --outFile parameter since 4c4087c6566becf9f7e8d9f38daafc0c07540ab8 committed.

I was use its well. So I wonder why it is changed.

Question

Most helpful comment

I've read all the above and still haven't a clue.

I've installed VS 2015 Update 2 which ships with 1.8, the rest of my team are on something older. They refuse to update because of some nonsense about importance of keeping the next release stable (!?) so is there a way to go back to an older version of TS?

Also, I don't even understand the problem and how it can work for everyone before and yet apparently the settings have never made any sense? It was clearly working somehow.

When we do move to 1.8 I still have no idea what the fix is. All the chatter above is saying how it "doesn't make sense" and not about how to resolve it.

All 26 comments

Are you perhaps confusing with --outDir ? --outFile (for modules) is new in 1.8 and never supported CommonJS - it doesn't make sense for CommonJS anyway since CJS modules cannot be concatenated.

I was use --out parameter in 1.7 with CommonJS.

If you mean that you want to compile CJS modules with the intent of compiling each .ts file to separate .js file, then you don't need to pass in the --outFile parameter at all.

in TS 1.7, --out/--outFile combined non-module code (i.e. files with no top-level import or export) to the --out/outFile parameter, where as all other modules are emitted to the their own files.

Obviously that was confusing to most users. Most ppl would thing of --out would really concatenate the output.

With TS 1.8, --out/--outFile is doing the more sensible concatenation (see What's new for more details).

Concatenation with commonJs does not make much sense, so is UMD, again because of how commonjs works, and this it is an error now to use --module commonjs + --out/--outFile

Concatenation with commonJs does not make much sense,

CommonJs expects files to exist at certain places, and changing their location breaks how they are loaded. moreover CommonJs/node modules have different scoping rules than script files, and concatenating them breaks that, so the only way to do this correctly is to wrap them in functions, and add a loader, which is pretty much AMD or system.js.

So I'm a bit behind the times - in our project we're using Typescript 1.4 which compiles/concatenates CommonJs modules into a single out file fine - we're using gulp-tsc to do this in a gulp file and doing the same using the Task Runner Explorer from VS 2015. It sometimes needs "hints" (using /// <reference path="foo.ts" /> comments at the top of certain files) but otherwise I've never had a problem with it.

Since we upgraded tsc on our build server to 1.8.2 however, the tsc refuses to do this anymore :-( I'm guessing there were issues in other commonjs projects that we never came across. So the solution is basically we have to move to system modules (no more commonjs)?

@jamescrosswell, that is a gulp-tsc question then. node modules were never concatenated by the compiler.

@mhegazy I don't think so. Looking at the source for gulp-tsc, all it's doing is adding the --out parameter when calling tsc... so it's relying on tsc to do it's thing under the hood.

Also, we just upgraded the typescript compiler in our project from 1.4.1 to 1.7.5 without any problem. So tsc appears only recently to have lost the ability to compile CommonJs modules into a single output file (i.e. with version 1.8).

just to be clear. before TS 1.8, --out will concatenate non-module files, i.e. files that do not have a top level import or export. modules, i.e. files with a top level import or export were never concatenated.

with TS 1.8, --out concatenates modules only for --module == amd | system. the concatenation of non-module files is not happening any more. is this what you are referring to?

I've read all the above and still haven't a clue.

I've installed VS 2015 Update 2 which ships with 1.8, the rest of my team are on something older. They refuse to update because of some nonsense about importance of keeping the next release stable (!?) so is there a way to go back to an older version of TS?

Also, I don't even understand the problem and how it can work for everyone before and yet apparently the settings have never made any sense? It was clearly working somehow.

When we do move to 1.8 I still have no idea what the fix is. All the chatter above is saying how it "doesn't make sense" and not about how to resolve it.

@lukepuplett I agree - i have exactly the same problem.

I dont know why they made this change so nonsensical - how can i go back to 1.7?

Could we please get an answer to this....

Has anyone above found a work-around to this annoyance?

how can i go back to 1.7?

what is the specific behavior that you need? do you have files with no imports or exports that were concatenated before?

Yes that's correct. I would like to have the same behavior as previously . Concatenated files.

in TS 1.7, modules (i.e. files with at least one import or export) were not concatenated. can you share a sample showing the expected behavior?

My understanding is that something we thought was working was not working, according to comments above. But 1.7 didn't prevent the nonsensical configuration so we never noticed.

Now, it is prevented in 1.8 but the problem is, I don't know what configuration I need to get the old behaviour. That's my question, really: what do I have to set make it compile exactly as it was doing before (whatever that was)? Thanks.

I'm in a situation where I cannot compile my team's code. The rest of the team don't want to update until there's a solution to this.

Sorry if i keep asking, but the original assumption was that no one had this scenario, and i want to understand more the details of your setup.
so you have some modules that use --module commonjs, and some non module files. you want to compile them all in the same go, but want the modules to go to their own files, and the non-module global code to be concatenated in one file. is this an accurate description?

Sorry Mohamed, are you asking me or ganySA?

either. is my description above accurately describe your scenario? can i look at your 1.7 project?

Okay, I'll have to chat to another guy on the team but I'm out of office all day tomorrow, so we're looking at Monday.

I've not been involved in the client-side (TS) stuff on this project much, I just happened to reinstall VS and end-up on v1.8. I've only brushed-up on 'commonjs' and the like since encountering this issue, so you'll have to excuse my ignorance.

thanks @lukepuplett, appreciate the help.

sorry for the delay in responding. in 1.7 I am using the visual studio property pages to define the TSC compiler options:-
Module System: None
Keep comments in JavaScript: yes
Combine javascript output to directory: $(ProjectDir)\xxx\yyy\app.js

for my teamcity build (and presumably 1.8 config {when we migrate}) I am using a tsconfig.json

{
  "compilerOptions": {
    "diagnostics": true,
    "noEmitOnError": true,
    "outFile": "../scripts/app.js",
    "module": "commonjs", // not relevant ... ignored by 1.7
    "target": "es5",
    "noImplicitAny": false,
    "rootDir": ".",
    "sourceMap": false
  },
  "exclude": [
    "node_modules"
  ]
}

So, are the VS settings of the file being used when TS 1.7 compiles it?

If the latter, then we need to know what settings to put in there that will work on 1.7 and 1.8 and produce the JS output in the same manner as its doing today.

@DavidNutstone if you are not using commonjs modules, remove "module": "commonjs" or set it to "module" : "none" instead. this should get you back to TS 1.7 behavior.

So, are the VS settings of the file being used when TS 1.7 compiles it?

Starting with TS 1.8, if you have a tsconfig.json in your project, it will be picked up over your project file, and all the settings in your project file will be ignored.
If this is not what you intend, remove the tsconfig.json from your project.

If the latter, then we need to know what settings to put in there that will work on 1.7 and 1.8 and produce the JS output in the same manner as its doing today.

  • remove or rename your tsconfig.json, build using your TS 1.7 settings (or just build on a VS instance using TS 1.7);
  • capture the build log (msbuild /verbosity:detailed).
  • in the build output you should see a call to tsc.exe with a set of arguments, something like:

C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7tsc.exe --sourcemap --target ES5 --noEmitOnError --locale en-US "c:users\mhegazy\documents\visual studio 2015\Projects\TypeScriptHTMLApp39\TypeScriptHTMLApp39\app.ts"`)

  • in your project folder, call tsc --init followed with the same arguments you had in your build log (e.g.

C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8tsc.exe --init --sourcemap --target ES5 --noEmitOnError --locale en-US "c:users\mhegazy\documents\visual studio 2015\Projects\TypeScriptHTMLApp39\TypeScriptHTMLApp39\app.ts"

  • this should create a tsconfig.json file for you. the file will have "exclude" and "files" properties. like:

json { "compilerOptions": { "sourceMap": true, "target": "es5", "noEmitOnError": true, "locale": "en-US", "module": "commonjs", "noImplicitAny": false }, "exclude": [ "node_modules" ], "files": [ "c:\\users\\mhegazy\\documents\\visual studio 2015\\Projects\\TypeScriptHTMLApp39\\TypeScriptHTMLApp39\\app.ts" ] }

  • now you have two options, either remove the "exclude" and make sure to add a file entry for every file you add your project, or remove the "files" property, and make sure to exclude any folders in your project that should not be included in the compilation, if there are any.

That's super, thanks for your time on this! Appreciated :)

Was this page helpful?
0 / 5 - 0 ratings