sous-chefs/nodejs

Upgraded NPM causes problems with npm install

Opened this issue ยท 1 comments

๐Ÿ—ฃ๏ธ Foreword

This is related to #245 , but adding bug Issue for visibility for others who might encounter it.

๐Ÿ‘ป Brief Description

With a recent version of NPM and it's push for deprecating -global, unfortunately it can cause problems when installing packages, because the warning still spits out, thus causing problems with expected JSON, this manifests in a client run with:

    * execute[install NPM package appcenter-cli] action run[2022-06-08T01:41:48-05:00] ERROR: nodejs::library::nodejs_helper::npm_list exception 785: unexpected token at ''

      
      ================================================================================
      Error executing action `run` on resource 'execute[install NPM package appcenter-cli]'
      ================================================================================
      
      NoMethodError
      -------------
      undefined method `[]' for false:FalseClass
      
      Cookbook Trace:
      ---------------
      /var/chef/cache/cookbooks/nodejs/libraries/nodejs_helper.rb:53:in `npm_package_installed?'
      /var/chef/cache/cookbooks/nodejs/resources/npm_package.rb:84:in `package_installed?'
      /var/chef/cache/cookbooks/nodejs/resources/npm_package.rb:54:in `block (3 levels) in class_from_file'
      
      Resource Declaration:
      ---------------------
      # In /var/chef/cache/cookbooks/nodejs/resources/npm_package.rb
      
       47:   execute "install NPM package #{new_resource.package}" do
       48:     cwd new_resource.path
       49:     command "npm install #{npm_options}"
       50:     user new_resource.user
       51:     group new_resource.group
       52:     environment npm_env_vars
       53:     live_stream new_resource.live_stream
       54:     not_if { package_installed? && no_auto_update? }
       55:   end
       56: end
      
      Compiled Resource:
      ------------------
      # Declared in /var/chef/cache/cookbooks/nodejs/resources/npm_package.rb:47:in `block in class_from_file'
      
      execute("install NPM package appcenter-cli") do
        action [:run]
        default_guard_interpreter :execute
        command "npm install  -global appcenter-cli@2.10.10"
        backup 5
        environment {"HOME"=>"/var/root", "USER"=>"root"}
        returns 0
        user "root"
        declared_type :execute
        cookbook_name "nodejs"
        domain nil
        not_if { #code block }
      end

There's a couple red-herrings in there, but believe I've tracked it down to https://github.com/sous-chefs/nodejs/blob/main/libraries/nodejs_helper.rb#L25

๐Ÿฅž Cookbook version

Likely 7.3.0 and up

๐Ÿ‘ฉโ€๐Ÿณ Chef-Infra Version

N/A

๐ŸŽฉ Platform details

Definitely impacts macOS

Steps To Reproduce

Have NPM 8.11 installed (supposedly that's the affected version)

๐Ÿš“ Expected behavior

Successful install

โž• Additional context

NPM : npm/cli#4980

There was a revert back to 8.12.1, but damage may already be done.

https://github.com/npm/cli/releases/tag/v8.12.1

Possible options :

  • incorporate this PR: #246
  • downgrade to NPM version (reports saying 7.x is fine, but lower 8.x < 8.11 might be ok as well)
  • force upgrade to ensure NPM > 8.12.1
    • This poses catch-22 if already on impacted version - no way to upgrade since getting the error