Grunt-shell task for Angular fails in VS Task Runner Explorer, but works in a command prompt

166 views Asked by At

I have a grunt script that is meant to kick off an Angular 2 build.

Running grunt on the command line succeeds - the Angular build runs as expected.

Running the task from Task Runner Explorer in VS 2017 fails.

The Gruntfile.js is as follows:

module.exports = function (grunt) {

    grunt.initConfig({

        shell: {
          options: {
            stderr: false
          },
          angularBuild: {
              command: 'ng build --prod'
          }
        }

    });

    grunt.loadNpmTasks('grunt-shell');

    grunt.registerTask('default', ['shell']);
};

The output in Task Runner Explorer is:

D:\Work> cmd.exe /c grunt -b "D:\Work" --gruntfile "D:\Work\Gruntfile.js" default --color
Running "shell:angularBuild" (shell) task
Warning: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "ng build --prod"
D:\Work\node_modules\@angular\cli\models\config\config.js:17
    constructor(_configPath, schema, configJson, fallbacks = []) {
                                                           ^
SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:404:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (D:\Work\node_modules\@angular\cli\models\config.js:3:18)
    at Module._compile (module.js:397:26)
    at Object.Module._extensions..js (module.js:404:10)
Use --force to continue.
Aborted due to warnings.
Process terminated with code 6.
1

There are 1 answers

0
DGreen On BEST ANSWER

Thanks to Mads Kristensen for pointing to his 2 year old blogpost - turns out VS was using a different version of the tools compared to the command prompt.

https://blogs.msdn.microsoft.com/webdev/2015/03/19/customize-external-web-tools-in-visual-studio-2015/