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

tsc apparently not picking up tsconfig.json #6591

Closed
jednano opened this issue Jan 23, 2016 · 7 comments
Closed

tsc apparently not picking up tsconfig.json #6591

jednano opened this issue Jan 23, 2016 · 7 comments

Comments

@jednano
Copy link
Contributor

jednano commented Jan 23, 2016

If I run:

$ tsc foo.ts

I get the following error:

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

In the same directory is my tsconfig.json file:

{
    "compilerOptions": {
        "module": "es2015",
        "target": "es2015"
    },
    "exclude": [
        "node_modules"
    ]
}

And here is the file I'm trying to compile:

export default function foo() {
    console.log('foo');
}

Now, if I manually provide the --module and --target flags, everything compiles as expected:

$ tsc --module es2015 --target es2015 foo.ts

Somehow, it's not picking up the tsconfig.json file compilerOptions?

$ tsc -v
message TS6029: Version 1.7.5
@falsandtru
Copy link
Contributor

What is the expected behavior?

@jednano jednano changed the title Cannot compile modules unless the '--module' flag is provided tsc apparently not picking up tsconfig.json Jan 23, 2016
@jednano
Copy link
Contributor Author

jednano commented Jan 23, 2016

That it compiles without errors? If I manually provide the --module es2015 and --target es2015 flags in the command then it compiles fine, so why isn't it picking up the compilerOptions in my tsconfig.json file?

@DanielRosenwasser
Copy link
Member

The problem is that tsconfig.json isn't considered when you manually specify your source files on the command line. It's certainly not great behavior, but I think it's by design since if you use the --project option, you'll get the following error:

error TS5042: Option 'project' cannot be mixed with source files on a command line.

@jednano
Copy link
Contributor Author

jednano commented Jan 25, 2016

Aha! Not very intuitive, but I suppose I can live with that. Still, I wonder if the error message could be improved to somehow indicate this to the user. Maybe whenever the tsc command is run, if it's run directly on files, an "info" message could show up that says something like, "Not using detected tsconfig.json". I think I'll open up an issue with this request. Thanks!

@DanielRosenwasser
Copy link
Member

I also opened #6600 for you @jedmao.

@gaurav21r
Copy link

@DanielRosenwasser
Is this a new change? Because VSCode stops compiling as per default instructions.

From Here https://code.visualstudio.com/Docs/languages/typescript

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"
}

The args parameter causes the exact issue @jedmao pointed out

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.

So, is the vscode doc wrong or is this a change in the recent versions of tsc?

@mhegazy
Copy link
Contributor

mhegazy commented Feb 3, 2016

So, is the vscode doc wrong or is this a change in the recent versions of tsc?

you can either pass file names to the compiler on the commandline, and the tsconfig.json will be ignored, or you can run tsc with no arguments and the tsconfig.json will be picked up automatically.

consider setting args to "--p <path to tsconfig.json>" instead.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants