neoclide / coc-eslint

Eslint extension for coc.nvim
MIT License
396 stars 26 forks source link

Unable to find global node modules #18

Closed edrpls closed 5 years ago

edrpls commented 5 years ago

Hi, first of all, thank you for all your work!

I cannot use local node_modules as I run my app inside a docker container and the modules are not shared with the host, and I've run into a problem where coc-eslint is unable to find the global node modules, even though I think it is properly configured.

Output of :version:

:version
NVIM v0.4.0-902-gb65a7b7f6
Build type: RelWithDebInfo
LuaJIT 2.0.5
Compilation: /usr/bin/gcc-5 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -DMIN_LOG_LEVEL=3 -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wvla -fstack-protector-strong -fdiagnostics-color=auto -Wno-array
-bounds -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/home/travis/build/neovim/bot-ci/build/neovim/build/config -I/home/travis/build/neovim/bot-ci/build/neovim/src -I/home/travis/build/neovim/bot-ci/build/neovim/.deps/usr/inclu
de -I/usr/include -I/home/travis/build/neovim/bot-ci/build/neovim/build/src/nvim/auto -I/home/travis/build/neovim/bot-ci/build/neovim/build/include
Compiled by travis@travis-job-aaa3286b-17a0-4354-95d2-447d580a1864

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/home/travis/build/neovim/bot-ci/build/neovim/build/nvim.AppDir/usr/share/nvim"

Run :checkhealth for more info

The output of npm root -g is:

/home/myUser/.npm-global/lib/node_modules

My coc-settings.json:

{
    "tsserver.npm":  "/home/myUser/.npm-global/lib/node_modules",
    "tsserver.trace.server":  "verbose",
    "coc.preferences.hoverTarget": "float",
    "coc.preferences.enableFloatHighlight": true,
    "coc.preferences.useQuickfixForLocations": true,
    "suggest.enablePreview": true,
    "tsserver.enable": true,
    "typescript.suggestionActions.enabled": false,
    "javascript.suggestionActions.enabled": false,
    "eslint.nodePath": "/home/myUser/.npm-global/lib/node_modules",
    "eslint.autoFixOnSave" : true,
    "eslint.packageManager" : "npm"
}

The first error I see when opening Neovim on javascript/jsx files:

Consider running eslint --debug /home/myUser/Projects/myDir/mySubDir/app/components/builder/QuestionHorizontalNav.jsx from a terminal to obtain a trace about the configuration files used.

Running the above suggestion from the terminal runs fine and returns no errors.

Running :CocCommand workspace.showOutput for eslint shows:

[Info  - 2:49:19 PM] ESLint server running in node v11.15.0
[Info  - 2:49:19 PM] ESLint library loaded from: /home/myUser/Projects/someProject/someSubDir/node_modules/eslint/lib/api.js
[Error  - 2:49:19 PM] 
Failed to load plugin react-hooks: Cannot find module 'eslint-plugin-react-hooks'
Happened while validating /home/myUser/Projects/someProject/someSubDir/app/components/builder/QuestionHorizontalNav.jsx
This can happen for a couple of reasons:
1. The plugin name is spelled incorrectly in an ESLint configuration file (e.g. .eslintrc).
2. If ESLint is installed globally, then make sure 'eslint-plugin-react-hooks' is installed globally as well.
3. If ESLint is installed locally, then 'eslint-plugin-react-hooks' isn't installed correctly.

Consider running eslint --debug /home/myUser/Projects/someProject/someSubDir/app/components/builder/QuestionHorizontalNav.jsx from a terminal to obtain a trace about the configuration files used.

Here's the output of ls /home/myUser/.npm-global/lib/node_modules:

babel-eslint
eslint
eslint-plugin-immutable
eslint-plugin-react
eslint-plugin-react-hooks
jscodeshift
livedown
node-gyp
npx
prettier
@types
webpack-bundle-analyzer

I do have the right modules installed globally, but for some reason coc-eslint is ignoring the global directory /home/myUser/.npm-global/lib/node_modules.

Am I missing something from the configuration?

Any help is appreciated, thank you!

chemzqm commented 5 years ago

Consider running eslint --debug /home/myUser/Projects/myDir/mySubDir/app/components/builder/QuestionHorizontalNav.jsx from a terminal to obtain a trace about the configuration files used.

edrpls commented 5 years ago

As I mentioned in the ticket originally, this command produces no errors, and everything runs fine from the terminal, the issue only occurs within neovim, running coc-eslint, please reopen the ticket.

chemzqm commented 5 years ago

if you have local eslint, install local plugins as well

edrpls commented 5 years ago

What is the case for setting a eslint.nodePath configuration if installing the local modules is required?

chemzqm commented 5 years ago

Can't reproduce

chemzqm commented 5 years ago

[Info - 2:49:19 PM] ESLint library loaded from: /home/myUser/Projects/someProject/someSubDir/node_modules/eslint/lib/api.js

edrpls commented 5 years ago

Yes, please read again my ticket, I mentioned that coc-eslint is trying to read the local modules instead of reading the globally installed modules set in coc-settings.json. I did look into all the warnings, I only opened this issue because the behavior from coc-eslint is inconsistent with the documentation, especifically with eslint.nodePath.

chemzqm commented 5 years ago

eslint.nodePath is fallback global module directory, it use local eslint module when possible, so it's expected.

use this setting if an installed ESLint package can't be detected.

Can you understand what can't be detected means?

edrpls commented 5 years ago

No need to attack, I do understand what can't be detected means, and to be honest I think there is some miscommunication or something is getting lost in translation here since I think none of us is a native speaker, I believe we both are making the same point, the modules don't exist locally, this is a limitation of my setup that I cannot change, but what I can do is install modules globally.

One would precisely think that

use this setting if an installed ESLint package can't be detected.

means setting eslint.nodePath is useful in my cases where local dependencies are not found, reason why I added this configuration.

I didn't mean to ruffle any feathers, I thought my original post included enough information to help debug this, as I have looked all the other tickets that even closely resemble mine and attempted all their solutions. I think most of what I wrote was ignored, and that's fine, OSS comes with no guarantees after all, but I do think it could've helped more people in the future, instead, pretty much everything I wrote was disregarded without a second thought.

Anyway, I appreciate the time you took and the software you've built.

chemzqm commented 5 years ago

/home/myUser/Projects/someProject/someSubDir/node_modules/eslint/lib/api.js

It's quite clear that eslint module exists in your project.

edrpls commented 5 years ago

Thanks for your response, the weird thing is that running ls on that dir returns nothing. Maybe this is caused by docker. I will try to ditch it for local development, as it is causing other issues. Sorry for the misunderstanding.