在终端中输入“ npm run debug”时,出现“ SyntaxError:无效或意外的令牌”

时间:2019-06-17 14:11:46

标签: node.js nightwatch

我是Node的新手,正在尝试设置Nightwatch,以便我可以运行自动化测试并练习我的测试技能。我还想澄清一下我在Windows 10计算机上。我目前在运行“ npm run debug”时遇到问题,因为在输入“ npx which nightwatch”并看到“ C:\ Users \ jtorres \ nightwatch-tests \ node_modules.bin \ nightwatch.CMD”后,将其设置为正确的目录。之后,我运行调试器并打开“ chrome:// inspect /#devices”以验证调试器是否运行并且运行正常,仅看到几条错误消息。我尝试将目录更改为“ node_modules / nightwatch / bin / nightwatch”,并制作了一个新的“ nightwatch.cmd”文件,以查看自动创建后是否存在错误,但是这些方法均无效。

错误:

(function (exports, require, module, __filename, __dirname) { @IF EXIST "%~dp0\node.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)

代码:

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\node.exe" (
  "%~dp0\node.exe"  "%~dp0\..\nightwatch\bin\nightwatch" %*
) ELSE (
  @SETLOCAL
  @SET PATHEXT=%PATHEXT:;.JS;=;%
  node  "%~dp0\..\nightwatch\bin\nightwatch" %*
)

1 个答案:

答案 0 :(得分:0)

您的"debug"参数中的路径错误。尝试改用它:

"debug": "node --inspect-brk node_modules/nightwatch/bin/nightwatch"