Why does the "SyntaxError: Unexpected ID" error occur when I use the Node.js interactive window in Visual Studio 2017?

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

On the command line, I have verified that my Node.js path is configured correctly and that I am pointing to the expected version. To do this, I ran:

node -v

      

and as expected I returned:

v6.11.1

      

I've also configured Visual Studio to use this version. To do this, I went to Tools> Options, added the root Node.js folder to my list of external web tools, and moved the path to the top of the list as shown in the following screenshot.

Options dialog box showing path locations for external web tools

I have verified that the Visual Studio toolkit is actually using this version by modifying the package.json file and checking that the packages are downloaded. Here is a screenshot showing that:

Visual Studio Solution Explorer showing downloaded NPM packages

I also launched a Node.js interactive window directly from my node project as shown in the screenshot below:

Project context menu showing Open Node.js Interactive window

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

Node.js Interactive window showing failed npm command

So my question is, why am I getting the "SyntaxError: Unexpected identifier" error?

+3


source to share


1 answer


Once I finished this question, I was able to speak to a colleague who said he was facing the same problem. For some strange reason (some of you may be commenting on this), the npm command must be prefixed with a period like this:

.npm install -g nsp

      



I find this completely unintuitive, but it solved my problem. Hope this helps someone else.

+4


source







All Articles