Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix eslint createRequire is not a function in Atom Editor?

I had a difficult time tracking this down, so I'm posting to help others who search for a similar error.


I decided to set up a new project on Ubuntu 18.04 in Atom with eslint and Node.js.

ESlint, by itself, installed and ran just fine with my config extending eslint:recommended, but when I installed eslint-config-airbnb-base and changed my config to extend airbnb-base, I started getting an error in Atom and it would not parse my files.

Error while running ESLint: createRequire is not a function.

Removing airbnb and relying on eslint-plugin-import gave a similar error:

Error while running ESLint: Failed to load plugin 'import' declared in '.eslintrc.yaml': createRequire is not a function.

However, running eslint on the command-line worked fine.

like image 216
chris Avatar asked Jul 14 '20 21:07

chris


1 Answers

This is a compatibility issue.

This change to eslint removed a polyfill that supported node versions below v10.12.0

I was running Atom 1.45.0, which uses node v10.11.0. Running eslint from the command line worked because I have node v12.18.2 installed there.

So you have two of options to fix the issue:

  1. Upgrade your Atom Editor (at the time of writing, version 1.49.0 is the latest, which uses node version v12.0.0). If that's not possible for you then...
  2. Downgrade eslint to version 6.8.0 (the last release before 7.0.0). This version still contains the polyfill for createRequire.
like image 63
chris Avatar answered Sep 22 '22 17:09

chris