Productivity — VS Code Setup in Windows 10

Micromike
The Startup
Published in
5 min readAug 11, 2020

Currently my Macbook air is not capable of what I want to do and I have change my laptop to a Windows 10 Machine due to the fact that I think Windows 10 has made so many new feature that made programming environment more friendly than Windows 7.

When I setup VS code with WSL, I have encounter some issues, and this post will walk through the issues and how I resoved them.

Story Begins…

When I first received my laptop, I started to setup the programming environment as I always do.

Different from the past, this time I decide to use VS Code instead of vim as my coding editor due to the reason that I have heard a lot of positive feedback of VS Code.

Setting up WSL and VS Code is very straight forward, and there are many online tutorial available so I will just skip this part.

After playing VS Code for a while, I have noticed a very strange issues.

Battery Drain

The very first thing that took my attention was that after opening VS Code, my laptops’s battery drain like a lot, way more than I expected.

My laptop battery indicator shows that it can only last about 2 hrs when VS Code is open.

In comparison, when I open chrome without VS Code, it should last about 10 hrs.

At first, I do not pay much attention to this issue.

I thought to myself

okay, just switch back to how I used to be: Install vim and everything works as I expected.

What I don’t realize at that time was that, this issue is caused by the same root cause that eventually haunt me later.

Rust Installation Failed

After the vim setup, I started installing the Rust compiler tool chain via the command provided by the rustup official websites.

And suddenly, an error occur, to my suprice rustup coredumped.

I got to say, I have using rustup for so many times, and I haven’t encounter one coredump at all.

Until now.

The rustup installation failed due to the follwoing coredump message.

info: installing component 'cargo'
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `22`,
right: `4`', src/libstd/sys/unix/thread.rs:166:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
thread 'main' panicked at 'assertion failed: `(left == right)`

After googling for a while, I realized that I’m not alone, other people have encounter this issue too.

I have found out the following github issues that describe the same problem.

It turns out that, WSL may not properly implement the nanosleep and Ubuntu 20.04 using a newer version of glibc that cause Rust Installation Failed.

It is the same reason that cause VS Code Remote extension for WSL using unexpected CPU usage and hence causing the battery drain.

Since VS code will run nodejs in WSL environment, and nodejs internally will use nanosleep to wait for a certain time and later to check the event loop’s event; as a result when glibc underline use nanosleep, nodejs can not sleep the current process and as a result keep occupying the CPU resource.

We can find out more github related issues that discuss with this problem.

To mitigate this issue one can either

Use WSL 2

Use Ubuntu 18.04 and not Ubuntu 20.04

Since my laptop can not use WSL2 yet, I reinstall Ubuntu with 18.04 and everything working normally.

NPM Module Installation Failed

After playing VS code for a while, I started to setup nodejs in the WSL environment.

When trying to call npm install, another error shows up.

npm ERR! Linux 3.4.0+
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "acorn"
npm ERR! node v5.10.1
npm ERR! npm v3.8.3
npm ERR! path ../acorn/bin/acorn
npm ERR! code EPERM
npm ERR! errno -1
npm ERR! syscall symlink

npm ERR! Error: EPERM: operation not permitted, symlink '../acorn/bin/acorn' -> '/mnt/r/path/node_modules/.bin/acorn'
npm ERR! at Error (native)
npm ERR! { [Error: EPERM: operation not permitted, symlink '../acorn/bin/acorn' -> '/mnt/r/path/node_modules/.bin/acorn']
npm ERR! errno: -1,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'symlink',
npm ERR! path: '../acorn/bin/acorn',
npm ERR! dest: '/mnt/r/path/node_modules/.bin/acorn',
npm ERR! parent: 'myproject' }
npm ERR!

After asking my best pale, Google, for advice, I found a workaround of this issue.

I have to close vscode first and using Windows Terminal to finish the npm installation

To 777 or Not to 777, It Is a Question

Finally, the last issue I encounter is that when create a folder (via mkdir) in WSL, the file permission will always be 777.

The following github issue describe the cause and how you can resolve this issue.

In WSL, there are two kind of filesystem

  • One for mount Windows native filesystem
  • One for Linux native filesystem

If you create folder in the Windows native filesystem, permission 777 is the expected behavior since Windows filesystem permission is not the same as linux.

However, in Linux native filesystem, the 777 is not what I expected and we can set umask to 22 to change it back to the way it should be (755).

Try to add an umak 22 to your shell configuration file(e.g. ~/.bashrc) and reload your shell(e.g. source ~/.bashrc), you should see that the mkdir work as expected.

Final Words

So far, I enjoy the developing experience with WSL + VS Code.

I’m impressed that Windows has change so much compare to 4 years ago (The old Windows 7 times).

Sometimes things might go wrong, but the process of investigate how to resolve these issues also let me learn a log of new stuff.

Hope the above information can help you and any feedback would be great.

--

--

Micromike
The Startup

Senior product developer in Synology. Programmer, #infosec enthusiasm, #linux, #python #Rust