Vscode: TypeScript build task fails when path to tsconfig.json file has spaces

Created on 19 Oct 2017  路  9Comments  路  Source: microsoft/vscode

  • VSCode Version: Code 1.17.2 (b813d12980308015bcd2b3a2f6efa5c810c33ba5, 2017-10-16T13:59:46.104Z)
  • OS Version: Windows_NT x64 10.0.15063

    - Extensions: none

Steps to Reproduce:

  1. Create a new folder with an space somewhere in the full path, lets say "D:TempSpace here"
  2. Add a dummy.ts file, it could be empty
  3. Add a tsconfig.json file, it could be just a pair of curly braces:
    { }
  4. Press Ctrl+Shift+P and type/select "Task: Configure Default Build Task" then select "tsc: build - tsconfig.json", the following "taks.json" is generated:
    {
            // See https://go.microsoft.com/fwlink/?LinkId=733558
            // for the documentation about the tasks.json format
            "version": "2.0.0",
            "tasks": [
                    {
                            "type": "typescript",
                            "tsconfig": "tsconfig.json",
                            "problemMatcher": [
                                    "$tsc"
                            ],
                            "group": {
                                    "kind": "build",
                                    "isDefault": true
                            }
                    }
            ]
    }
  1. Execute the build command with Ctrl+Shift+B shortcut
    The following error message is displayed:
    > Executing task: tsc -p "d:\Temp\Space here\tsconfig.json" <

    error TS5042: Option 'project' cannot be mixed with source files on a command line.
    The terminal process terminated with exit code: 1

    Terminal will be reused by tasks, press any key to close it.
  1. Now close VS
  2. Rename the folder to remove the white space
  3. Execute the build command from VS again, now it works:
    > Executing task: tsc -p "d:\Temp\Space_NOT_here\tsconfig.json" <

    Terminal will be reused by tasks, press any key to close it.

Additional information:
Although the displayed command looks fine and will actually work if you Copy&Paste it into a Terminal window: tsc -p "d:TempSpace heretsconfig.json"
the error message is consistent with what you'd get if you remove the quotes, which suggests they weren't there when the command was actually executed as a task by VS

EDIT: fix markdown issue

bug tasks verified

Most helpful comment

To verify:

  • create workspace folder with space in its name
  • create a tsconfig.json and TS file
  • execute the tsc build task (no need to create on. It is the one provided by the TS extension)

All 9 comments

This is a little bit a chicken egg problem which we were discussing how to best solve. The problem is that the creator of the task doesn't know which shell is used to execute hence doesn't really no how to quote / escape these things and the task executing engine doesn't know the structure of the command. The only possible way I can imagine is that the creator of the tasks give hint which parts should be escaped.

Same problem on macOS. As a workaround I'm launching tsc as type shell command:

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

Fixed in latest.

To verify:

  • create workspace folder with space in its name
  • create a tsconfig.json and TS file
  • execute the tsc build task (no need to create on. It is the one provided by the TS extension)

@dbaeumer I stumbled over this issue aswell and was wondering if that is in insider yet cause even with insider it breaks for me but with a different error:

VS 1.21.1 had:

> Executing task: c:\Dev\chromajs sample\node_modules\.bin\tsc.cmd --watch -p "c:\Dev\chromajs sample\tsconfig.json" <

c:\Dev\chromajs : The term 'c:\Dev\chromajs' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
At line:1 char:1
+ c:\Dev\chromajs sample\node_modules\.bin\tsc.cmd --watch -p c:\Dev\ch ...
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (c:\Dev\chromajs:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

VS 1.22.0-insider with commit hash that is 19 hours ago (a716373aaaf50cbce3618688a645b324721b35dd):

> Executing task: 'c:\Dev\chromajs sample\node_modules\.bin\tsc.cmd' --watch -p 'c:\Dev\chromajs sample\tsconfig.json' <

At line:1 char:54
+ 'c:\Dev\chromajs sample\node_modules\.bin\tsc.cmd' --watch -p 'c:\Dev ...
+                                                      ~~~~~
Unexpected token 'watch' in expression or statement.
At line:1 char:1
+ 'c:\Dev\chromajs sample\node_modules\.bin\tsc.cmd' --watch -p 'c:\Dev ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The '--' operator works only on variables or on properties.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

Without spaces everything works fine....

I will reopen the issue.

OK. I only tested it with a global installed tsc. Need to dig why --watch now is interpreted as an expression in PowerShell.

OK. If the command is quoted I need to put a & in front :-)

@WolfspiritM thanks for bringing that to my attention

Was this page helpful?
0 / 5 - 0 ratings