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


I have been using VSCode a lot lately. I have recently started delving into TypeScript and wanted to use VSCode to begin developing my first project. I was following a tutorial on Lynda.com and for the life of me could not get it to “transpile” my TS project. I setup everything according to this site and it failed. What I kept getting was this error:

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

This error is all over the web and not a single solution helped. I am guessing it is caused by the fact I have VS2015, VS2017, and VSCode installed on my box. But, this is the weird thing, if I go to the PowerShell in the Terminal window and paste the EXACT command that VSCode uses… IT WORKS!!! What? I started puling my hair out at this point…

Ok, now that really sucked. So, I got fed up and just build my own tasks.json using the “Other” option and here is what I entered:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "DaveCra TSC Task for VSCode",
            "command": "tsc -p tsconfig.json",
            "type": "shell",
            "problemMatcher": [
                "$tsc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

Once I set this up, it was the default build task and a CTRL+SHIFT+B ran fine. Right after that I was able to go to the PowerShell terminal and type “node ” and it ran like a charm. wlEmoticon-hotsmile.png

2 thoughts on “VSCode: error TS5042: Option ‘project’ cannot be mixed with source files on a command line.

  1. Thanks you so much for this. I am also just started learning Typescript and was following a tutorial and could not for the life of me get past that error as well. I was loosing my mind. Thank you!!!

  2. Same as Nigel,

    I checked that I could directly on shell type ” tsc -p ./ ” and was getting the tsconfig by it’s own.
    I’m using VS Code and wasn’t letting me get the task config for type: typescript that I configured.

    Thank you so much

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s