voxpupuli / puppet-nodejs

Puppet module to install nodejs and global npm packages
https://forge.puppet.com/puppet/nodejs
Apache License 2.0
113 stars 248 forks source link

Cannot install packages with npm provider on Windows #454

Open voom opened 2 years ago

voom commented 2 years ago

Affected Puppet, Ruby, OS and module versions/distributions

How to reproduce (e.g Puppet code you use)

I'm trying to install node-red package on my Windows machine using npm provider

class { 'nodejs': }

package { 'node-red':
    ensure          => 'present',
    provider        => 'npm',
    install_options => ['--unsafe-perm'],
    require         => Class['nodejs'],
}

What are you seeing

I'm getting the following error: Package[node-red]: Provider npm is not functional on this host

But both NodeJS and npm are installed on the system and added to PATH:

PS C:\> node -v; npm -v
v17.5.0
8.4.1

What behaviour did you expect instead

I'm expecting to be able to install npm packages on Windows machine

voom commented 2 years ago

I found the solution how to fix "Provider npm is not functional on this host" error. It's also important to note that npm packages are installed into the systemprofile APPDATA directory by default: C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\npm

So, if we add the following location to the PATH, this will fix npm and allow us to install npm packages:

$env:PATH += ";C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\npm"

Node.js and NPM versions:

PS C:\> node -v; npm -v
v16.14.2
8.5.0

This is the working manifest (requires puppet-windows_env module):

  class { 'nodejs':
    repo_url_suffix       => '16.x',
    nodejs_package_ensure => '16.14.2',
  }

  $appdata = $facts['windows_env']['APPDATA']

  windows_env { "PATH=${appdata}\\npm":
    ensure    => present,
    mergemode => insert,
    require   => Class['nodejs']
  }

  package { 'node-red':
    ensure          => 'present',
    provider        => 'npm',
    install_options => ['--unsafe-perm'],
    require         => Class['nodejs'],
  }
voom commented 2 years ago

I've a question after my recent update. Should be the PATH env. variable configuration (or maybe the npm prefix change in config) be a part of the puppet-nodejs module configuration?