Why do I get a "SyntaxError: Unexpected identifier" error when I use the Node.js Interactive Window in Visual Studio 2017?

Viewed 5040

I'm new to Node.js and npm and I'm trying to configure a JavaScript development environment in Visual Studio 2017. I have downloaded and installed the latest recommended version of Node.js (currently v6.11.1).

From a command prompt I verified that my Node.js path is configured correctly and that I am pointing at the expected version. To do this I ran:

node -v

and as expected I got back:

v6.11.1

I also configured Visual Studio to use this version. To do that I went to Tools > Options, added the Node.js root folder to my list of External Web Tools, and moved the path to the top of the list as you see in the following screenshot.

Options Dialog showing External Web Tools Path Locations

I have verified that the Visual Studio tooling is in fact using this version by modifying my package.json file and verifying that the packages have downloaded. Here is a screenshot showing that:

Visual Studio Solution Explorer showing downloaded NPM packages

I also launched the Node.js Interactive Window directly from my project node as is shown in the screenshot below:

Project context menu showing Open Node.js Interactive Window option

But when I try to run an npm command from the interactive window I get a "SyntaxError: Unexpected identifier" error like the screenshot below:

Node.js Interactive Window showing failed npm command

So my question is – Why do I get a "SyntaxError: Unexpected identifier" error?

2 Answers

The NPM command must be prefixed with a dot and I am doing the same in my local machine' VS 2013's Node application. It is working for me when adding dot as prefix.

Related