Tuesday 16 May 2017

Unable to run babel-node on Windows

I would appreciate it if someone could help me figure out what is causing the error mentioned below.

I have a test Express project with a scripts section in package.json that looks like the following:

"scripts": {
   "dev": "backpack",
   "build": "backpack build",
   "test-server": "babel-node node_modules/.bin/babel-istanbul cover node_modules/.bin/_mocha",
   "test-server-ms": "babel-node.cmd node_modules/.bin/babel-istanbul.cmd cover node_modules/.bin/_mocha.cmd"
},

The test-server-ms script is what I am trying to execute:

babel-node.cmd node_modules/.bin/babel-istanbul.cmd cover 
      node_modules/.bin/_mocha.cmd "test/server"

This yields an error when parsing the babel-istanbul.cmd file:

(function (exports, require, module, __filename, __dirname) { @IF EXIST "%~dp0\node.exe" (
                                                              ^
SyntaxError: Invalid or unexpected token
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Module._extensions..js (module.js:579:10)
    at Object.require.extensions.(anonymous function) [as .js] (C:\Users\hqrsingh\Development\workspaces\vscode\express-es6-starter\node_modules\babel
-register\lib\node.js:152:7)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Function.Module.runMain (module.js:604:10)
    at Object.<anonymous> (C:\Users\hqrsingh\Development\workspaces\vscode\express-es6-starter\node_modules\babel-cli\lib\_babel-node.js:154:22)

The error occurs when the @IF directive is encountered which is part of a Windows .cmd script in node_modules\.bin\babel-istanbul.cmd:

@IF EXIST "%~dp0\node.exe" (
  "%~dp0\node.exe"  "%~dp0\..\babel-istanbul\lib\cli.js" %*
) ELSE (
  @SETLOCAL
  @SET PATHEXT=%PATHEXT:;.JS;=;%
  node  "%~dp0\..\babel-istanbul\lib\cli.js" %*
)

I am kicking all of this off within a Windows 7 Pro command shell via npm:

 npm run-script test-server-ms test/server

For reference, here is the entire package.json file:

{
  "name": "express-es6-starter",
  "version": "2.0.0",
  "description": "A complete boilerplate for Express.js development including unit test and code coverage.",
  "main": "lib/index.js",
  "scripts": {
    "dev": "backpack",
    "build": "backpack build",
    "test-server": "babel-node node_modules/.bin/babel-istanbul cover node_modules/.bin/_mocha",
    "test-server-ms": "babel-node.cmd node_modules/.bin/babel-istanbul.cmd cover node_modules/.bin/_mocha.cmd"
  },
  "pre-commit": [
    "test-server"
  ],
  "dependencies": {
    "express": "^4.14.0"
  },
  "devDependencies": {
    "babel": "^6.23.0",
    "babel-cli": "^6.24.1",
    "babel-istanbul": "^0.12.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-0": "^6.16.0",
    "babel-preset-stage-2": "^6.24.1",
    "backpack-core": "^0.0.7",
    "chai": "^3.5.0",
    "karma": "^1.7.0",
    "karma-chrome-launcher": "^2.1.1",
    "karma-jasmine": "^1.1.0",
    "karma-phantomjs-launcher": "^1.0.4",
    "mocha": "^3.2.0",
    "phantomjs": "^2.1.7",
    "pre-commit": "^1.2.2",
    "webpack": "^1.14.0"
  }
}



via Rai

No comments:

Post a Comment