0

I'm using Visual Studio Code 1.13.0 on Windows 10.
I have the following build script in my package.json:

{
  //omitted other props
  "scripts": {
    "build": "webpack"
  }
}

I've installed webpack with npm install --global webpack, so it's installed globally.

The webpack.config.js is irrelevant for my question.

When I run npm run build in the terminal, everything works fine. But when I run the Visual Code Tasks: Run Build Task (ctrl+shift+b or ctrl+shift+p > Run Build Task), then I'm getting the following message in the output window:

'"npm run build"' is not recognized as an internal or external command, operable program or batch file.

Why? (using npm version: 3.10.10)

3
  • Which OS are you using? Commented Jun 13, 2017 at 6:56
  • Also, what are the contents of ` tasks.json`? Commented Jun 13, 2017 at 7:00
  • I didn't have tasks.json, somehow I thought this was not needed and built in into Visual Code and that the command would recognize the package.json. Commented Jun 14, 2017 at 7:30

2 Answers 2

5
+100

You should create tasks.json file and specify build task with npm task runner as described here ctrl+shift+p > Configure Task Runner. In your case task.json file should looks something like that

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "npm",
    "isShellCommand": true,
    "showOutput": "always",
    "suppressTaskName": true,
    "tasks": [
        {
            "isBuildCommand": true,
            "taskName": "build",
            "args": ["run", "build"]
        }
    ]
}
Sign up to request clarification or add additional context in comments.

1 Comment

The isShellCommand is now outdated. The "type": "npm" is the new format.
3

tasks.json can be used for running multiple different tasks. This is @oleg-m's answer updated for version 2 of tasks.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type":"npm",
            "script": "build",
            "group": "build"
        }
    ]
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.