Can't install nodemon on WSL2

Viewed 136

I am learning node.js, and I tried to install nodemon to practice, but in WSL2 (ubuntu) I can't install or run it. If I try to install or run the same project with Windows it works, but when I open the same project in WSL2 it shows errors or warnings:

ubuntu@DESKTOP-254V119:~/lecture/lec69$ npm install nodemon
loadDep:update-notifier → ▌ ╢█████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
WARN engine update-notifier@5.1.0: wanted: {"node":">=10"} (current: {"node":"8.10.0","npm":"3.loadDep:fsevents → addNam ▌ ╢█████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
WARN engine fsevents@2.3.2: wanted: {"node":"^8.16.0 || ^10.6.0 || >=11.0.0"} (current: {"node"loadDep:semver → resolveW ▀ ╢███████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
loadDep:xdg-basedir → 304 ▀ ╢███████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
loadDep:xdg-basedir → get ▌ ╢███████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
WARN engine is-installed-globally@0.4.0: wanted: {"node":">=10"} (current: {"node":"8.10.0","npm":"3.5.2"})
loadDep:xdg-basedir → 304 ▐ ╢███████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
loadDep:wrap-ansi → 304   ▄ ╢███████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
WARN engine camelcase@6.3.0: wanted: {"node":">=10"} (current: {"node":"8.10.0","npm":"3.5.2"})
WARN engine type-fest@0.20.2: wanted: {"node":">=10"} (current: {"node":"8.10.0","npm":"3.5.2"})
loadDep:is-path-inside →  ▌ ╢████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟)
WARN engine global-dirs@3.0.0: wanted: {"node":">=10"} (current: {"node":"8.10.0","npm":"3.5.2"loadDep:ini → 304         ▐ ╢████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
loadDep:lru-cache → 304   ▄ ╢████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟

> nodemon@2.0.15 postinstall /home/ubuntu/lecture/lec69/node_modules/nodemon
> node bin/postinstall || exit 0

lec69@1.0.0 /home/ubuntu/lecture/lec69
└── nodemon@2.0.15  extraneous

npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@2.3.2
npm WARN lec69@1.0.0 No repository field.

This is my package.json file:

{
  "name": "lec69",
  "version": "1.0.0",
  "description": "this is bad",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "awsome"
  ],
  "author": "arjun",
  "license": "ISC"
}

I am learning node.js, and every developer I see says that Linux is good for web development. I tried it, and this is the first error I see.

I am new to Linux so I don't know if I am doing something wrong or is it something else. LOL, I even checked my spelling.

2 Answers

Remember to read the errors and warning messages closely:

wanted: {"node":">=10"} (current: {"node":"8.10.0"

It looks to me like you are on Ubuntu 18.04 under WSL and installed via sudo apt install nodejs.

8.10.0 is the latest node version that is available in the apt repositories for that release, which is not enough for nodemon apparently.

Note that the Ubuntu releases that are available for WSL are what are known as "Long Term Support" (LTS) releases. This means (among other things) that they are well-tested with a certain set of software releases which are then typically only updated with security patches. As a result, you typically won't find the latest releases of any software in the repositories. Ubuntu 18.04 was released almost 4 years ago, which is of course a long time in web-dev. LTS releases are done every two years, in April, so the 22.04 release is imminent at this point.

You'll be better off using at least Ubuntu 20.04 under WSL. It supports node 10.19.0, which is sufficient for nodemon.

You'll also be even better off using a "node version manager" of some sort that can install (and switch between) multiple Node releases independent of apt. The most popular (IMHO) is nvm, but I personally use n myself.

Note: I have some "throwaway" WSL instances that I used to confirm this. I can reproduce your error on 18.04, but I can't install nodemon using the repo-available Node.js under 20.04.

Related