eslint: Error while running ESLint: Invalid regular expression flags

Tell us about your environment

  • ESLint Version: 6.6.0
  • Node Version: 12.13.0
  • npm Version: 6.12.0

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration:

Configuration
env:
  browser: true
  es6: true
  node: true
extends:
  - standard
globals:
  Atomics: readonly
  SharedArrayBuffer: readonly
parserOptions:
  ecmaFeatures:
    jsx: true
  ecmaVersion: 2018
  sourceType: module
plugins:
  - react
rules: {}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint. Creating any *.js file trigger the error. My linter in Atom report the following

What did you expect to happen? No linter error flag when a JS file is created

What actually happened? Please include the actual, raw output from ESLint.

Error while running ESLint: Invalid regular expression flags
Invalid regular expression flags
Referenced from: /Users/me/dev/.eslintrc.yml

/Users/me/dev/node_modules/eslint/lib/source-code/source-code.js:426
return /\s/u.test(text.replace(/\/\*.*?\*\//gus, ""));
                               ^

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 11
  • Comments: 23 (7 by maintainers)

Most upvoted comments

The related lint-eslint plugin issue is at https://github.com/AtomLinter/linter-eslint/issues/1306 . This led me to update Atom to version 1.42, which fixed the problem.

I think that I know how to solve the issue, at least with WebStorm it works. It looks like Webstorm grabs on startup default Node/NPM version. If you manage multiple Node/NPM versions by nvm and the default one is v8.9.1 like in my scenario it won’t work.

To fix it you need to go to: Webstorm -> Preferences -> Languages and Frameworks -> Node.js and NPM and select correct Node interpreters, see screenshot below:

Screen Shot 2019-11-17 at 18 47 21

See also: #12493. Please re-check node version used.

Same issue, using Node v12.8.0. Works fine with npx eslint *.js, but there’s an error loading eslint in Atom. But downgrading to eslint@6.5.0 makes Atom work fine.

Same here:

/Users/kostia/Code/scrivito_js/js/node_modules/eslint/lib/source-code/source-code.js:426
        return /\s/u.test(text.replace(/\/\*.*?\*\//gus, ""));
                                       ^

SyntaxError: Invalid regular expression flags
  at createScript (vm.js:80:10)
  at Object.runInThisContext (vm.js:139:10)
  at Module._compile (module.js:599:28)
  at Object.Module._extensions..js (module.js:646:10)
  at Module.load (/Users/kostia/Code/scrivito_js/js/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
  at tryModuleLoad (module.js:497:12)
  at Function.Module._load (module.js:489:3)
  at Module.require (module.js:579:17)
  at require (internal/module.js:11:18)
  at Object.<anonymous> (/Users/kostia/Code/scrivito_js/js/node_modules/eslint/lib/source-code/index.js:4:17)
  at Module._compile (module.js:635:30)
  at Object.Module._extensions..js (module.js:646:10)
  at Module.load (/Users/kostia/Code/scrivito_js/js/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
  at tryModuleLoad (module.js:497:12)
  at Function.Module._load (module.js:489:3)
  at Module.require (module.js:579:17)
  at require (internal/module.js:11:18)
  at Object.<anonymous> (/Users/kostia/Code/scrivito_js/js/node_modules/eslint/lib/linter/linter.js:25:22)
  at Module._compile (module.js:635:30)
  at Object.Module._extensions..js (module.js:646:10)
  at Module.load (/Users/kostia/Code/scrivito_js/js/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
  at tryModuleLoad (module.js:497:12)
  at Function.Module._load (module.js:489:3)
  at Module.require (module.js:579:17)
  at require (internal/module.js:11:18)
  at Object.<anonymous> (/Users/kostia/Code/scrivito_js/js/node_modules/eslint/lib/linter/index.js:3:20)
  at Module._compile (module.js:635:30)
  at Object.Module._extensions..js (module.js:646:10)
  at Module.load (/Users/kostia/Code/scrivito_js/js/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
  at tryModuleLoad (module.js:497:12)
  at Function.Module._load (module.js:489:3)
  at Module.require (module.js:579:17)
  at require (internal/module.js:11:18)
  at Object.<anonymous> (/Users/kostia/Code/scrivito_js/js/node_modules/eslint/lib/cli-engine/cli-engine.js:25:20)
  at Module._compile (module.js:635:30)
  at Object.Module._extensions..js (module.js:646:10)
  at Module.load (/Users/kostia/Code/scrivito_js/js/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
  at tryModuleLoad (module.js:497:12)
  at Function.Module._load (module.js:489:3)
  at Module.require (module.js:579:17)
  at require (internal/module.js:11:18)
  at Object.<anonymous> (/Users/kostia/Code/scrivito_js/js/node_modules/eslint/lib/cli-engine/index.js:3:23)
  at Module._compile (module.js:635:30)
  at Object.Module._extensions..js (module.js:646:10)
  at Module.load (/Users/kostia/Code/scrivito_js/js/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
  at tryModuleLoad (module.js:497:12)
  at Function.Module._load (module.js:489:3)
  at Module.require (module.js:579:17)
  at require (internal/module.js:11:18)
  at Object.<anonymous> (/Users/kostia/Code/scrivito_js/js/node_modules/eslint/lib/api.js:8:23)
  at Module._compile (module.js:635:30)
  at Object.Module._extensions..js (module.js:646:10)
  at Module.load (/Users/kostia/Code/scrivito_js/js/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
  at tryModuleLoad (module.js:497:12)
  at Function.Module._load (module.js:489:3)
  at Module.require (module.js:579:17)
  at require (internal/module.js:11:18)
  at ForkTsCheckerWebpackPlugin.validateEslint (/Users/kostia/Code/scrivito_js/js/node_modules/fork-ts-checker-webpack-plugin/lib/index.js:173:23)
  at new ForkTsCheckerWebpackPlugin (/Users/kostia/Code/scrivito_js/js/node_modules/fork-ts-checker-webpack-plugin/lib/index.js:88:53)
  at module.exports (/Users/kostia/Code/scrivito_js/js/webpack.config.js:152:7)
  at module.exports.karma (/Users/kostia/Code/scrivito_js/js/karma/base.js:15:19)
  at module.exports.karma (/Users/kostia/Code/scrivito_js/js/karma.conf.js:10:3)
  at Object.parseConfig (/Users/kostia/Code/scrivito_js/js/node_modules/karma/lib/config.js:395:5)
  at new Server (/Users/kostia/Code/scrivito_js/js/node_modules/karma/lib/server.js:67:24)
  at Object.exports.run (/Users/kostia/Code/scrivito_js/js/node_modules/karma/lib/cli.js:295:7)
  at Object.<anonymous> (/Users/kostia/Code/scrivito_js/js/node_modules/karma/bin/karma:3:23)
  at Module._compile (module.js:635:30)
  at Object.Module._extensions..js (module.js:646:10)
  at Module.load (module.js:554:32)
  at tryModuleLoad (module.js:497:12)
  at Function.Module._load (module.js:489:3)
  at Function.Module.runMain (module.js:676:10)
  at startup (bootstrap_node.js:187:16)
  at bootstrap_node.js:608:3

I have the same issue when I used create-react-app and opened the app in Atom. The difference is I have an error flag (Error while running ESLint: Invalid regular expression flags) on the first line of every file even if it is empty. The program will run fine but the ugly error is there. What I’ve tried: I updated to Node 12 and it didn’t work. I have another react app I had been working on for a year now that had an older version of ESlint so I decided to downgrade it and see if that would fix it since my old app had no such error. In doing so I got an error telling me I can not manually downgrade when using create-react-app so I had to remove and reinstall the package-lock.json and node modules to make it whole again. I tried using ESlint ignore line but no luck. I don’t want the eyesore and I can’t seem to be able to fix it. If anyone has a solution, hmu.

I have the same issue with Node v12.13.0 using Webstorm

Correct, I’m using Node v12.13.0 through nvm

In the v4.19.1, I experienced the same error from the file and line at /lib/source-code/source-code.js:426

The return statement of the function isSpaceBetweenTokens on the return line the following code return /\s/u.test(text.replace(/\/\*.*?\*\//gus, "")); should be return /\s/u.test(text.replace(/\/\*.*?\*\//, "gus"));

This solved the problem for me but the function in the most recent src seems to be depreciated.