'SyntaxError: Invalid or unexpected token' Appears When Entering 'npm run debug' in Terminal
Asked 07 September, 2021
Viewed 2K times
  • 61
Votes

I am new to Node and am trying to set up Nightwatch so I can run automated tests and practice my testing skills. I also want to clarify that I am on a Windows 10 computer. I am currently having issues with running 'npm run debug' as I have it set to the correct directory after entering 'npx which nightwatch' and seeing 'C:Usersjtorres ightwatch-tests ode_modules.bin ightwatch.CMD'. Afterwards, I run the debugger and open 'chrome://inspect/#devices' to verify that the debugger runs and is functioning properly, only to see several error messages. I have tried changing the directory to 'node_modules/nightwatch/bin/nightwatch' and made a new 'nightwatch.cmd' file to see if there was an error after it was created automatically, but none of these methods have worked.

Errors:

(function (exports, require, module, __filename, __dirname) { @IF EXIST "%~dp0
ode.exe" (
                                                              ^

SyntaxError: Invalid or unexpected token
    at new Script (vm.js:80:7)
    at createScript (vm.js:274:10)
    at Object.runInThisContext (vm.js:326:10)
    at Module._compile (internal/modules/cjs/loader.js:664:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
    at startup (internal/bootstrap/node.js:283:19)

Code:

package.json file - 
    {
      "name": "nightwatch-tests",
      "version": "1.0.0",
      "description": "",
      "main": "sample.js",
      "scripts": {
        "lint": "eslint .",
        "debug": "node --inspect-brk C:/Users/jtorres/nightwatch-tests/node_modules/.bin/nightwatch.CMD",
        "test": "nightwatch"
      },
      "keywords": [],
      "author": "",
      "license": "ISC",
      "devDependencies": {
        "chromedriver": "^75.0.0",
        "nightwatch": "^1.1.12"
      }
    }

nightwatch.CMD file - 
@IF EXIST "%~dp0
ode.exe" (
  "%~dp0
ode.exe"  "%~dp0..
ightwatchin
ightwatch" %*
) ELSE (
  @SETLOCAL
  @SET PATHEXT=%PATHEXT:;.JS;=;%
  node  "%~dp0..
ightwatchin
ightwatch" %*
)

1 Answer