Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot install packages with npm provider on Windows #454

Open
voom opened this issue Feb 16, 2022 · 2 comments
Open

Cannot install packages with npm provider on Windows #454

voom opened this issue Feb 16, 2022 · 2 comments

Comments

@voom
Copy link

voom commented Feb 16, 2022

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 6.21.1
  • Ruby: -
  • Distribution: Windows 10 Pro
  • Module version: 9.0.1

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
Copy link
Author

voom commented Mar 29, 2022

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
Copy link
Author

voom commented Apr 5, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant