IDE on Ubuntu thinks npm is not installed, but it is installed together with nodejs

Building a nodejs Toradex IDE package on Ubuntu 22.04 build machine:


Checking dependencies ...
πŸ‘ openssh-client debian package dependency installed
πŸ‘ sshpass debian package dependency installed
πŸ‘ nodejs debian package dependency installed
😡 npm debian package dependency not installed
Try to install the missing debian packages and execute the missing installation scripts? <y/N>: y
[sudo] password for workuser: 
Hit:1 https://download.docker.com/linux/ubuntu jammy InRelease
Hit:2 https://deb.nodesource.com/node_22.x nodistro InRelease                   
Hit:3 https://packages.microsoft.com/ubuntu/22.04/prod jammy InRelease          
Hit:4 http://security.ubuntu.com/ubuntu jammy-security InRelease                
Hit:5 http://archive.ubuntu.com/ubuntu jammy InRelease              
Hit:6 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:7 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:8 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Reading package lists... Done
W: https://packages.microsoft.com/ubuntu/22.04/prod/dists/jammy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 npm : Depends: node-agent-base but it is not going to be installed
       Depends: node-aproba but it is not going to be installed
       Depends: node-archy but it is not going to be installed
       Depends: node-cacache but it is not going to be installed
       Depends: node-chalk but it is not going to be installed
       Depends: node-cli-table3
       Depends: node-colors but it is not going to be installed
       Depends: node-columnify but it is not going to be installed
       Depends: node-debug but it is not going to be installed
       Depends: node-emoji-regex
       Depends: node-got but it is not going to be installed
       Depends: node-graceful-fs but it is not going to be installed
       Depends: node-gyp but it is not going to be installed
       Depends: node-https-proxy-agent but it is not going to be installed
       Depends: node-mkdirp but it is not going to be installed
       Depends: node-ms but it is not going to be installed
       Depends: node-nopt but it is not going to be installed
       Depends: node-normalize-package-data but it is not going to be installed
       Depends: node-npm-package-arg but it is not going to be installed
       Depends: node-npmlog but it is not going to be installed
       Depends: node-read-package-json but it is not going to be installed
       Depends: node-rimraf but it is not going to be installed
       Depends: node-semver but it is not going to be installed
       Depends: node-ssri but it is not going to be installed
       Depends: node-string-width but it is not going to be installed
       Depends: node-strip-ansi but it is not going to be installed
       Depends: node-tar but it is not going to be installed
       Depends: node-validate-npm-package-name but it is not going to be installed
       Depends: node-which but it is not going to be installed
       Depends: node-write-file-atomic but it is not going to be installed
       Depends: nodejs:any (>= 10)
       Recommends: node-tap but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
❌ error trying to install package npm

 *  The terminal process "pwsh '-nop', '/home/workuser/workspace/qedge/qedgesio/.conf/checkDeps.ps1'" terminated with exit code: 69.

But node and npm are there:


workuser@toradex:~/workspace/testproject/testprojectsio$ node -v
v22.8.0
workuser@toradex:~/workspace/testproject/testprojectsio$ npm -v
10.8.2

In fact sudo apt-get list show only nodejs, not npm, but this is something that happens in latest nodejs versions (in my case, 22.8):

$  apt list --installed  | grep node

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
nodejs/nodistro,now 22.8.0-1nodesource1 amd64 [installed]
$ apt list --installed  | grep npm

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

How can we have that fixed? I cannot work with nodejs that comes with Ubuntu (12.x), as my code need newer versions.

This is how I’ve installed node (to get 22.x version):

curl -sL https://deb.nodesource.com/setup_22.x -o /tmp/nodesource_setup.sh
sudo bash /tmp/nodesource_setup.sh
sudo apt-get install nodejs -y

I’ve tried to install npm only:

sudo apt-get install npm
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 npm : Depends: node-agent-base but it is not going to be installed
       Depends: node-aproba but it is not going to be installed
       Depends: node-archy but it is not going to be installed
       Depends: node-cacache but it is not going to be installed
       Depends: node-chalk but it is not going to be installed
       Depends: node-cli-table3
       Depends: node-colors but it is not going to be installed
       Depends: node-columnify but it is not going to be installed
       Depends: node-debug but it is not going to be installed
       Depends: node-emoji-regex
       Depends: node-got but it is not going to be installed
       Depends: node-graceful-fs but it is not going to be installed
       Depends: node-gyp but it is not going to be installed
       Depends: node-https-proxy-agent but it is not going to be installed
       Depends: node-mkdirp but it is not going to be installed
       Depends: node-ms but it is not going to be installed
       Depends: node-nopt but it is not going to be installed
       Depends: node-normalize-package-data but it is not going to be installed
       Depends: node-npm-package-arg but it is not going to be installed
       Depends: node-npmlog but it is not going to be installed
       Depends: node-read-package-json but it is not going to be installed
       Depends: node-rimraf but it is not going to be installed
       Depends: node-semver but it is not going to be installed
       Depends: node-ssri but it is not going to be installed
       Depends: node-string-width but it is not going to be installed
       Depends: node-strip-ansi but it is not going to be installed
       Depends: node-tar but it is not going to be installed
       Depends: node-validate-npm-package-name but it is not going to be installed
       Depends: node-which but it is not going to be installed
       Depends: node-write-file-atomic but it is not going to be installed
       Depends: nodejs:any (>= 10)
       Recommends: node-tap but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Naturally can’t as node is already installed using curl.

Thanks for helping.

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


It looks like the issue you’re encountering is due to the way the Node.js and npm packages are being managed on your Ubuntu system. The Node.js version you installed from the NodeSource repository does not include npm as a separate package, which is why your IDE is not recognizing it.

Here are a few steps you can take to resolve this issue:

  1. Install npm separately using NodeSource:
    Since you already have Node.js installed from NodeSource, you can install npm separately using the following command:

    sudo apt-get install npm
    
  2. Use n or nvm to manage Node.js and npm:
    Instead of using the NodeSource repository, you can use n or nvm (Node Version Manager) to manage your Node.js and npm installations. These tools allow you to easily switch between different versions of Node.js and npm.

    • Using n:

      sudo npm install -g n
      sudo n latest
      
    • Using nvm:

      curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
      source ~/.bashrc
      nvm install node
      
  3. Verify npm installation:
    After installing npm, verify that it is correctly installed and recognized by your system:

    npm -v
    
  4. Check for broken packages:
    If you still encounter issues, you might have broken packages on your system. You can try to fix them using the following commands:

    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install -f
    
  5. Manually install missing dependencies:
    If the issue persists, you can manually install the missing dependencies listed in the error message. For example:

    sudo apt-get install node-agent-base node-aproba node-archy node-cacache node-chalk node-cli-table3 node-colors node-columnify node-debug node-emoji-regex node-got node-graceful-fs node-gyp node-https-proxy-agent node-mkdirp node-ms node-nopt node-normalize-package-data node-npm-package-arg node-npmlog node-read-package-json node-rimraf node-semver node-ssri node-string-width node-strip-ansi node-tar node-validate-npm-package-name node-which node-write-file-atomic
    

By following these steps, you should be able to resolve the issue with npm not being recognized by your IDE on Ubuntu 22.04.

Please, also check if these links can help you solve your problem:

Transitioning to Torizon IDE Extension.

Greetings @renatom,

I believe the dependency checker in our IDE extension uses dpkg to determine whether certain packages are installed or not: vscode-torizon-templates/scripts/checkDeps.ps1 at dev Β· toradex/vscode-torizon-templates Β· GitHub

That would explain why the dependency checker is behaving this way since you installed node/npm outside of the usual package manager. Let me check with our IDE extensions team if there is a way to workaround this somehow.

Best Regards,
Jeremias

According to our team, you should be able to just ignore the missing dependency warning message and proceed with your VSCode project. As long as the package/utility is installed by some other means, which you have.

Can you confirm whether you can proceed with your development by just ignoring this missing dependency message?

If the message does bother you, you can also remove npm from the list of dependencies in the deps.json file of your project. That way the check for this dependency will just be skipped.

Best Regards,
Jeremias

This is how I’ve solved it.

Had deinstalled nodejs from apt-get and used only nvm to install the version I need. Now working fine.

Glad to hear you were able to resolve things.