polygonplanet/sublime-text-eslint

Error: Cannot find module 'eslint'

programmist opened this issue ยท 18 comments

I'm getting the following error when I try to run ESLint within Sublime 3.

module.js:472
    throw err;
    ^

Error: Cannot find module 'eslint'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/userx/Library/Application Support/Sublime Text 3/Packages/ESLint/linter.js:11:17)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
[Finished in 0.1s with exit code 1]
[cmd: ['node', '/Users/userx/Library/Application Support/Sublime Text 3/Packages/ESLint/linter.js', '/Users/userx/workspace/react/first-app/src/App.js', '', '']]
[dir: /Users/userx/workspace/react/first-app/src]
[path: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin]

Steps to Reproduce:

  • npm install -g eslint
  • Install ESLint ST3 plugin
  • Add Setting: "node_path": "/usr/local/bin"
  • Add Setting: "node_modules_path": "/usr/local/lib/node_modules"
  • Open JS file in ST3
  • Right-click->ESLint

System:

  • OS X 10.12.2
  • node 7.5.0 (also tried on 5.7.x)
  • eslint 3.16.0
  • sublime-text-eslint 4.0.0

This may be a regression of #2, but unfortunately the discussion in that issue did not help me.

Thank you.

Maybe your node_modules pass does not match.
You can check your global node_modules path by

$ npm root -g

command. and try set your sublime eslint's "node_modules_path" to displayed path.

Thank you. I checked both both paths before setting them in Sublime. When I run npm root -g I get
/usr/local/lib/node_modules, which is what I have set for node_modules_path.

Does the following command output something in your environment? or empty?

$ echo $NODE_PATH

The latest versions of node and npm no longer add the global node_modules directory to $NODE_PATH. See this.

Could this package be updated to use the eslint binary installed by npm install eslint -g directly? It looks like this is how the sublime-jshint package handles this.

Running npm link eslint in the Sublime ESLint package directory appears to provide a temporary workaround.

@polygonplanet Apologies, I'd forgotten to reply. My NODE_PATH env variable is not set.

$ echo $NODE_PATH

$

@jkirkwood thanks for your hint!
@programmist OK, As in nodejs document, if the following pass is valid, try setting "node_modules_path": "$HOME/.node_modules" etc.

  1. $HOME/.node_modules
  2. $HOME/.node_libraries
  3. $PREFIX/lib/node

Or, try to set "node_modules_path": "", and enter following command in terminal:

cd YOUR_SUBLIME_ESLINT_PACKAGES_FOLDER
# example: cd /Users/userx/Library/Application Support/Sublime Text 3/Packages/ESLint
npm link eslint

I'm good if you want to close this. Or let me know and I'll close it. Thanks for your help.

I just tried to install ESLint, and got the same error. Upon running npm link eslint in my ESLint package folder, I now get:
/usr/local/lib/node_modules/eslint/lib/util/module-resolver.js:74
throw new Error(Cannot find module '${name}'\);
^

Error: Cannot find module 'babel-eslint'
at ModuleResolver.resolve (/usr/local/lib/node_modules/eslint/lib/util/module-resolver.js:74:19)
at loadFromDisk (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:544:42)
at Object.load (/usr/local/lib/node_modules/eslint/lib/config/config-file.js:592:20)
at Config.getLocalConfigHierarchy (/usr/local/lib/node_modules/eslint/lib/config.js:228:44)
at Config.getConfigHierarchy (/usr/local/lib/node_modules/eslint/lib/config.js:182:43)
at Config.getConfigVector (/usr/local/lib/node_modules/eslint/lib/config.js:287:21)
at Config.getConfig (/usr/local/lib/node_modules/eslint/lib/config.js:330:29)
at processText (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:162:33)
at processFile (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:245:18)
at executeOnFile (/usr/local/lib/node_modules/eslint/lib/cli-engine.js:585:25)

@mdaross-ha Did you install eslint npm install -g eslint ?

jt3k commented

same problem

I got same problem

manually:

// C:\Users\<USERNAME>\AppData\Roaming\Sublime Text 3\Packages\User\ESLint.sublime-settings
{
  "node_modules_path": "C:\\Users\\<USERNAME>\\AppData\\Roaming\\npm\\node_modules",
}

If the problem is not solved yet, we want to know more detail.
We close this issue once.

If you're still facing issue after adding node_modules_path. Restart Sublime Text!

installing eslint and babel-eslint locally ( using --save option ) worked for me.

Running npm link eslint in the Sublime ESLint package directory appears to provide a temporary workaround.

Thanks ! :)