Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript compile error in tasks.json #140

Closed
gaurav21r opened this issue Feb 3, 2016 · 7 comments
Closed

Typescript compile error in tasks.json #140

gaurav21r opened this issue Feb 3, 2016 · 7 comments
Labels
Milestone

Comments

@gaurav21r
Copy link

According to https://github.com/Microsoft/vscode-docs/blob/master/docs/languages/typescript.md#tsconfigjson

The first TypeScript example uses tsc (the TypeScript compiler) as the command to be executed. > The task we are working with looks something like this:

{
    "version": "0.1.0",
    "command": "tsc",
    "isShellCommand": true,
    "showOutput": "silent",
    "args": ["HelloWorld.ts"],
    "problemMatcher": "$tsc"
}

But VSCode stops compiling TypeScript as per default instructions. The args parameter causes the issue

foo.ts(1,25): error : Cannot compile modules unless the '--module' flag is provided.

When I remove args everything is working! This is because the fileName is being supplied to tsc as a command line argument and it ignores tsconfig.json.

Refer to microsoft/TypeScript#6591

On the other hand, supplying no parameters, compiles all the files given in my tsconfig.json. I am using tsc v 1.7.5

Can i open a PR for this if you can verify the error?

@gregvanl
Copy link

gregvanl commented Feb 3, 2016

Hi Gaurav,
The document instructions work for me. Maybe I haven't understood your scenario but could this be as simple as the task example is building HelloWorld.ts and you're trying to build foo.ts?
I tested with es2015 as well as ES5 and amd.
tsconfig.json
{
"compilerOptions": {
"target": "es2015",
"module": "es2015",
"sourceMap": true
}
}

@gregvanl gregvanl closed this as completed Feb 3, 2016
@gaurav21r
Copy link
Author

Hi Greg! Sorry the discrepancy between HelloWorld.ts and foo.ts is because I copy pasted from 2 different sources! microsoft/TypeScript#6591 and https://github.com/Microsoft/vscode-docs/blob/master/docs/languages/typescript.md#tsconfigjson My bad!

@gregvanl My point is as @mhegazy says in microsoft/TypeScript#6591 if we pass args to tasks.json, tsconfig.json is ignored! What is the tsc version you are using? I am using 1.7.5 on Win10. VSCode is 0.10.6.

@egamma
Copy link
Member

egamma commented Feb 4, 2016

@gregvanl the example works fine. Since HelloWorld.ts doesn't use modules it doesn't need a tsconfig.json. Therefore the task definition where the file to compile is passed as an argument is OK.

However, what is somewhat confusing is that the doc introduces the tsconfig.json and then the task definition is done without even mentioning the tsconfig.json.

I suggest to mention that when your project has a tsconfig.json then do not pass the file name as an argument. Since tsc will takes this information from the tsconfig.json.

@egamma egamma reopened this Feb 4, 2016
@gaurav21r
Copy link
Author

@egamma @gregvanl How about removing this param from the example completely? I am not using args at all and it just compiles TS as is given in the tsconfig.json. If you agree, I'd like to open a PR.

@egamma
Copy link
Member

egamma commented Feb 4, 2016

How about removing this param from the example completely?

When removing the param then example is no longer self contained since it then depends on a tsconfig.json. This would be fine when the doc also includes the corresponding tsconfig.json. In this case the tsconfig.json would be empty since no compiler option needs to defined, which I don't like. So I suggest to make the example more interesting let's make the example a very simple node example so that the tsconfig.json includes the module attribute set to commonjs.
Then the doc could still mention that when your project has no tsconfig.json you can pass in the arguments using the 'args` attribute.

@gaurav21r
Copy link
Author

@egamma Yeah, you are right! There can be users who don't have a tsconfig.json though unlikely! We can give an example of a simple node module's tsconfig.json as you suggested 👍 Can we simply point to the TypeScript's repo's / site's tsconfig.json documentation? So users would know what they can include in tsconfig.json? Ideally, I see very few use cases where people would even use the args in this case. Makes more sense to use it for build tasks like LESS Compile etc.

@egamma
Copy link
Member

egamma commented Feb 4, 2016

Yes we should link to the tsconfig.json doc from TypeScript and not duplicate it.https://github.com/Microsoft/TypeScript/wiki/tsconfig.json

Actually, this is already done in the section above,

Explicit Project: a TypeScript project is defined via a tsconfig.json file. The presence of such a file in a directory indicates that the directory is the root of a TypeScript project. The file itself lists the files belonging to the project as well as compiler options. Details about the tsconfig.json file can be found here.

but repeating it doesn't hurt

@gregvanl gregvanl added the small label Jan 11, 2017
@gregvanl gregvanl added this to the April 2017 milestone Apr 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants