Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 903
jlavallet Avatar asked Jul 21 '17 19:07

jlavallet


People also ask

How do you fix an unexpected identifier syntax error?

To solve the "Uncaught SyntaxError: Unexpected identifier" error, make sure you don't have any misspelled keywords, e.g. Let or Function instead of let and function , and correct any typos related to a missing or an extra comma, colon, parenthesis, quote or bracket.

What does SyntaxError unexpected identifier mean?

"Unexpected identifier" means that you have a variable you're trying to reference that hasn't been declared. Make sure you pass all the variables you're trying to use into your template. All reactions.

How do you fix the term NPM is not recognized?

The error “npm is not recognized as an internal or external command” error may occur because either the npm is not installed or it is not added to the windows path. To resolve this error, the first solution is to install Node. js on Windows as Node. js is equipped with npm by default.


1 Answers

As I was just finishing up this question I was able to speak with a colleague who said that he ran across the same problem. For some strange reason (maybe some of you experts can comment on this) the npm command must be prefixed with a dot like this:

.npm install -g nsp

I find this completely nonintuitive, but it solved my problem. I hope this will help someone else.

like image 167
jlavallet Avatar answered Sep 28 '22 07:09

jlavallet