a pleasant descent into madness

Tag: node

host angular web-app in wsl2, access from windows host, develop in vs-code

Or: How do i work in a modern, efficient and really really nice way?

The goal of this article is to set up a system where you will be running an angular web application in WSL2 and access it via a Browser on the Windows Host.
It’s pretty straightforward, because i prepared a little something.

Prepare following docker-compose.yml file (which you want to place somewhere on the same file-system level as your application, or above it, not below!)

image: cryptng/angular:node14ng13
– ./my-angular-app:/app
– “4200:4200”
command: bash -c “npm install -f –loglevel verbose && ng serve –verbose — watch=true –host= –proxy-config proxy.config.json –disable-host-check”
version: ‘3.5’

You WILL have to fix the indentation to match yml standards.

You might notice that we are using an existing image from the docker hub.
It’s actually a repository that i manage and maintain with a friend.
If you check it out in detail, you will notice that this images matches the latest
angular-web-development standards as per november of 2021 (nearing the end of the corona crisis, probably, maybe).

The image basically uses Node:14 as a base image, containing NPM and YARN, and installs Angular-CLI 13 and Angular-Core 13 on a local and global level, then exposes port 4200.


Of course, you can easily modify the “ports” section of the compose file to change the port you want to serve to, the LEFT side is the host side.

That means that if you run this compose file with a valid application, you will be able to reach your application from a browser on the windows host via “http://localhost:4200”.
If you change the LEFT element from 4200 to 4201, the address will be “http://localhost:4201” independently from the actual EXPOSE command in the dockerfile providing the container.

bash -c “npm install -f –loglevel verbose && ng serve –verbose — watch=true –host= –proxy-config proxy.config.json –disable-host-check”

This command assumes you have a proxy.config.json in the application directory, remove the –proxy-config proxy.config.json part if you do not have a backend running on the windows host, else, create a proxy.config.json and configure it to lead to the windows host.

The npm command will install all dependencies whenever the docker-compose has been run.

Now, if you also want to be developing in visual studio code, install it in your WSL and run
“code path-to-your-app-directory/. “
it will open VS code in this directory, vs code will automagically understand that this is an angular application and will give you some prompts depending on its complexity and components.

If you now have a valid application in the “my-angular-app” directory, you can have fun and start developing.


Fix “Unsupported platform for fsevents” in npm

When trying to install npm packages via “npm install”, you might encounter an error “EBADPLATFORM”

npm ERR! notsup Unsupported platform for fsevents@1.1.3: wanted 

This Error is indicating that you are installing the fsevents module in another OS rather than Mac, but the fsevents module only works for Mac OS.
If you did not purposefully include fsevents in your package.json, this hints at a sub-dependency.

To fix this error, you can use following parameters in the npm install command:

npm install -f --loglevel verbose 

The loglevel will help you debug any further problems. “-f” will force npm to fetch remote resources even if a local copy exists on disk.

I was unable to obtain information on how this fix actually corrects the sub-dependency issue, i could guess, but that doesn’t really help anyone.

If anyone has an explanation that’s more than just guessing, please feel free to leave a comment!

© 2022 Yavuz-Support Blog

Theme by Anders NorenUp ↑