22

I am new to Node.js, npm and sublime environment and I am finding it difficult to integrate ESlint with sublime editor.

The steps which I followed is as follows:

  1. Installed ESLint with command: npm install -g eslint
  2. Installed ESLint with Sublime package control

Now getting following error in Sublime editor:

module.js:327
    throw err;
    ^

Error: Cannot find module 'eslint'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (C:\Users\MyUser\AppData\Roaming\Sublime Text 3\Packages\ESLint\linter.js:12:17)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
[Finished in 0.2s with exit code 1]
user2692032
  • 771
  • 7
  • 26

6 Answers6

28

Go to "Preferences / Package Settings / ESLint / Settings - User" in the menu bar, and enter the following (file paths may vary):

{
  "node_path": "/usr/local/bin",
  "node_modules_path": "/usr/local/lib/node_modules"
}

Here's the GitHub page: https://github.com/polygonplanet/sublime-text-eslint. Scroll down to the "Configuring ESLint" section, it's all documented there.

Jeremy Bernier
  • 1,746
  • 1
  • 17
  • 17
2

If Jeremy's answer still doesn't help, make sure your npm folder is exposed in your environment variable.

On Windows 7, PATH would include something like:

C:\Users\<YOUR_USERNAME>\AppData\Roaming\npm;

(Location: Control Panel\All Control Panel Items\System\Advanced system settings\Advanced\Environment Variables\User variables...\PATH)

ellockie
  • 3,730
  • 6
  • 42
  • 44
2

I got ESlint working for me on Sublime Text 3 and Win 7 by editing the file "Preferences -> Package Settings -> ESLint -> Settings - Default" file, inserting an additional 3rd value for the 'Config File' as you can see in the screen-shot below:

Steps to follow for setting up ESlint on Sublime Text 3 with Win 7+

The file code would look like this, if you don't want to see the screen-shot:

{ "node_path": "C:/Program Files/nodejs",
"node_modules_path": "C:/Users/<UserName>/AppData/Roaming/npm/node_modules",
"config_file": "C:/Users/<UserName>/AppData/Roaming/npm/node_modules/eslint/node_modules/debug/.eslintrc"}

You can further see which file formats are supported for configuration here: https://eslint.org/docs/user-guide/configuring

Iqtidar Ali
  • 179
  • 1
  • 6
1

Not sure, if this issue has been solved in the meanwhile, but there has been a discussion some years ago, about installing eslint globally or locally per project. As far as I understood the discussion, it is recommended to install eslint and eslint plugins locally to avoid the issue.

In order to use Eslint with Sublime, I installed eslint in my project with:

npm install eslint --save-dev

Furthermore I installed SublimeLinter and SublimeLinter-eslint to integrate the Eslint into Sublime and let it run whenever a file is saved.

auralbee
  • 8,741
  • 4
  • 29
  • 36
0

This error is what npm would throw if it doesn't find the eslint module.

I had the same error and I realized that it was for incorrect node_modules_path, it "$HOME/.npm-global" and I just change that to "$HOME/.npm-global/bin"(+"/bin") and it worked for me.

Madmadi
  • 2,064
  • 1
  • 14
  • 17
0

i encountered that issue installing: npm install -g eslint solved that problem in next way:

  1. get known Eslint version from terminal;

    eslint -v
    
  2. added a line to dependencies in package.json with that known eslint version

    "dependencies": {
    ...
    "eslint": "^4.19.1"
    }
    
  3. final step : in terminal i updated all written in this package.json

    npm install
    
Alexey Nikonov
  • 4,958
  • 5
  • 39
  • 66