简体   繁体   中英

ESLint on VSCode using WSL

I'd like to setup my dev environment for Node.js on Windows, using the Windows Subsystem for Linux as much as possible.

I've installed Node.js and ESLint on WSL and Visual Studio Code, with the ESLint extension on Windows.

But when I open VSCode, I get this message error from the ESLint extension:

Failed to load the ESLint library for the document c:\PATH\TO\FILE.js
To use ESLint for single JavaScript file install eslint globally using 'npm install -g eslint'.
You need to reopen VS Code after installing eslint.

The only way to make it work is to install Node.js ( and ESLint ) for Windows too?

There is a way to make this work.

After installing nodejs inside WSL, use the following commands to setup NPM:

mkdir ~/.npm-global
npm config set prefix ~/.npm-global
echo 'PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.profile
. ~/.profile

If you're using Ubuntu as your distro for WSL, make sure you have installed eslint globally inside your WSL:

npm install -g eslint

Next, add this setting to VSCode:

"eslint.nodePath": "C:/Users/YOURUSERNAME/AppData/Local/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState/rootfs/home/UBUNTUUSERNAME/.npm-global/lib/node_modules"

Make sure to replace the path with your Windows username and your Ubuntu username. This will point VSCode to your eslint location inside WSL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM