"npm run lint" fails on Windows #8021

Open
andrerpena opened this Issue Oct 19, 2016 · 3 comments

Projects

None yet

3 participants

@andrerpena

"npm run lint" fails on Windows, at least Windows 7.

Error:

Running "eslint" task
[17:46:07] Using gulpfile C:\Projetos\Git\react\gulpfile.js
[17:46:07] Starting 'eslint'...
C:\Projetos\Git\react\node_modules.bin\eslint.cmd:1
(function (exports, require, module, __filename, __dirname) { @IF EXIST "%~dp0\node.exe" (
^
SyntaxError: Unexpected token ILLEGAL
at Object.exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:513:28)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.runMain (module.js:575:10)
at run (node.js:348:7)
at startup (node.js:140:9)
at node.js:463:3
[17:46:08] Lint failed
Fatal error: Something went wrong running gulp:

Screenshot:

image

I found this "related" error in mocha but I couldn't fix it anyway.

What might it be?

@jddxf
Contributor
jddxf commented Nov 7, 2016

I encountered the same problem. If you look into the code in gulp/tasks/eslint.js, you'll find the following code:

spawn(
      process.execPath,
      [
        path.join('node_modules', '.bin', 'eslint' + extension),
        '.',
      ],
      {
        // Allow colors to pass through
        stdio: 'inherit',
      }
    )

which spawns a new process using the command "node node_modules.bin\eslint.cmd .". The command tries to interpret a batch file using node. However node can interpret js files only. That's why there's a SyntaxError.
A change like this should work as expected:

spawn(
      path.join('node_modules', '.bin', 'eslint' + extension),
      ['.'],
      {
        // Allow colors to pass through
        stdio: 'inherit',
      }
    )
@gaearon
Member
gaearon commented Nov 8, 2016

@jddxf Would you like to send a PR if you have a working fix?

@jddxf
Contributor
jddxf commented Nov 9, 2016

@gaearon Sure. I'll fix the same problem in gulp flow task too.

@jddxf jddxf added a commit to jddxf/react that referenced this issue Nov 9, 2016
@jddxf jddxf #8021
Fix gulp tasks: eslint and flow error on Windows
8d03339
@gaearon gaearon added a commit that referenced this issue Nov 9, 2016
@jddxf @gaearon jddxf + gaearon #8021 (#8241)
Fix gulp tasks: eslint and flow error on Windows
8267e11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment