M1 error getting installed npm version: error running npm command: No preset version installed for command npm

Description of the issue

Hello,

Just recently, using the Run NPM step stopped working on my M1 Medium Bitrise pipeline. It gives me the following error:

Config:
- Workdir: /Users/vagrant/git/app
- Command: ci
- NpmVersion: 
- UseCache: false
Autodetecting npm version
Checking package.json for npm version
Could not read version information from package.json
Locating system installed npm
npm found at /Users/Vagrant/.asdf/shims/npm
$ npm "--version"
error getting installed npm version: error running npm command: No preset version installed for command npm
Please install a version by running one of the following:
asdf install nodejs 14
or add one of the following versions in your config file at /Users/vagrant/.tool-versions
nodejs 12.22.9
nodejs 16.19.1
nodejs 19.8.1

which is weird, because I have a Script step earlier in the pipeline that using npm explicitly like and it succeeds:

+ npm install -g appium@next --unsafe-perm=true --allow-root
npm WARN deprecated typedoc-plugin-resolve-crossmodule-references@0.3.3: Upgrade to typedoc >= 0.24 and remove typedoc-plugin-resolve-crossmodule-references from your dependencies
added 423 packages, and audited 424 packages in 22s
48 packages are looking for funding
  run `npm fund` for details
7 moderate severity vulnerabilities
To address all issues (including breaking changes), run:
  npm audit fix --force
Run `npm audit` for details.
Reshimming asdf nodejs...
+ appium driver install uiautomator2
- Installing 'uiautomator2' using NPM install spec 'appium-uiautomator2-driver'
āœ” Installing 'uiautomator2' using NPM install spec 'appium-uiautomator2-driver'
ā„¹ Driver uiautomator2@2.28.0 successfully installed
- automationName: UiAutomator2
- platformNames: ["Android"]

Environment:

Where did the issue happen?

Itā€™s running on BitRise
Xcode 14.1.x, on macOS 13.2 (Ventura) M1 Medium

Which build Step causes the issue and which version of the step?

Run NPM Command v1.1.6 (I also tried 1.1.4)

Reproducibility

  • Does a ā€œRebuildā€ help? (You can trigger a rebuild from the Buildā€™s page, by clicking the ā€œRebuildā€ button in the top right corner of a finished build) : NO
  • Does a rebuild without caches help? (You can remove the Cache:Pull and Cache:Push steps temporarily to not to use the cache, or you can delete all the caches on the Settings tab of the app. : NO
  • Does the issue happen sporadically, or every time? : Every time
  • Does upgrading the build Step to the latest version help? : NO
  • When did the issue start? : Today (June 22, 2023)

Local reproduction

Can it be reproduced on your own Mac/PC by following our local debug guide? Please follow at least the first section (ā€œTesting with a full clean git cloneā€) to make sure to test the state of the code what bitrise.io will get when it does a git clone in the clean environment! If possible please note which sections you tried.

No

Local reproduction: Linux / Android (docker based) stack builds

Itā€™s not on Linux or Docker.

Build log

4 Likes

New info, this appears to only be happening in the git directory.

I have logged into the machine running the pipeline using the Remote Access instructions (Remote access - Bitrise Docs) and when I run npm --version in the home directory, I get that itā€™s version 8.19.3 but when I go into the git directory, then it complains:
image

1 Like

The same problem started occurring for us since yesterday. We were able to solve it by deleting the .nvmrc file in our project.

3 Likes

I managed to work around this issue by copying the .tool-versions file found in /Users/vagrant into /Users/vagrant/git with the following step right before the npm command:

    - script@1:
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully
            set -o pipefail
            # debug log
            set -x

            # write your script here
            cp ../.tool-versions ./.tool-versions

            # or run a script from your repository, like:
            # bash ./path/to/script.sh
            # not just bash, e.g.:
            # ruby ./path/to/script.rb

The important bit is cp ../.tool-versions ./.tool-versions

If you are using the workflow editor on bitrise, you simply need to run that command with the ā€œScriptā€ step

2 Likes

I have submitted a ticket to their support, hopefully this issues gets taken care of soon. Itā€™s not fun to come back from a weekend with your builds failing :sweat_smile:

I started getting the same error but for node

ā€œNo preset version installed for command nodeā€

Adding a .tool-versions file to my repository fixed it for me.

1 Like

I fixed the npm --version error with your solution but my unit tests are unable to run with this error
TypeError: Cannot assign to read only property 'performance' of object '[object global]' at Object.<anonymous> (node_modules/react-native/jest/setup.js:401:20)

anybody have this same issue?

Response from the bitrise team to the ticket:

I apologize for the inconvenience, our recent stack update brought some changes, notably our use of ASDF as the Ruby version manager. asdf was already in use on our stacks but one of the issues that users are facing is that If the project has a .node-version file in the project root, ASDF now tries to activate that version. Previously this file was ignored.

I have seen users resolve this by removing the .node-version alternatively you can add a script (step) that uses asdf to install the desired version.

asdf install nodejs <version you want>
asdf global nodejs <version you want>

I hope this information is useful, apologies for the inconvenience once again.

2 Likes

Hello,

Iā€™ve been facing the problem that my Workflow has to use ruby ā€œ3.1.0ā€. So according to [Ruby versions on Bitrise - Bitrise Docs](https://bitrise ruby guide), I added this as a script stepā€¦

asdf install ruby 3.1.0
# bitrise said "ruby 3.1.0 is already installed" šŸ˜‘
asdf global ruby 3.1.0

But I noticed that even though add a step and install and global, I found not be able to run these commands, fastlane, pod, gem.

So Iā€™ve checked what shims are exist.

# After asdf install, asdf global... even asdf reshim
+ ls /Users/vagrant/.asdf/shims
appcenter
bin-proxy
bundle
bundler
commander
cordova
corepack
dotenv
erb
fastlane
fuzzy_match
gem
go
gofmt
httpclient
ionic
irb
jazzy
jmespath.rb
mustache
node
nokogiri
npm
npx
pod
racc
racc2y
rake
rbs
rdbg
rdoc
react-native
redcarpet
ri
rougify
ruby
sandbox-pod
slather
terminal-notifier
trainer
typeprof
ww
xcodeproj
xcov
xcpretty
xcpretty-json-formatter
xcpretty-travis-formatter
xcversion
y2racc
šŸŽ‰
+ ls /Users/vagrant/.asdf/installs/ruby/3.1.0/bin/
bundle
bundler
erb
gem
irb
racc
rake
rbs
rdbg
rdoc
ri
ruby
typeprof
+ ls /Users/vagrant/.asdf/installs/ruby/3.2.2/bin/
bin-proxy
bundle
bundler
commander
dotenv
erb
fastlane
fuzzy_match
gem
httpclient
irb
jazzy
jmespath.rb
mustache
nokogiri
pod
racc
rake
rbs
rdbg
rdoc
redcarpet
ri
rougify
ruby
sandbox-pod
slather
terminal-notifier
trainer
typeprof
ww
xcodeproj
xcov
xcpretty
xcpretty-json-formatter
xcpretty-travis-formatter
xcversion
šŸŽ‰

Then I checked asdf has changedā€¦

+ which ruby
/Users/Vagrant/.asdf/shims/ruby
+ ruby -v
ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [arm64-darwin21]
+ asdf current ruby
ruby            3.1.0           /Users/vagrant/.tool-versions

But I will get somethingā€¦

gem install fastlane
/var/folders/69/qgnyrbkx23dbp0p6p_b6bc9m0000gn/T/bitrise289696288/step_src/._script_cont: /Users/vagrant/.asdf/installs/ruby/3.1.0/bin/gem: /Users/vagrant/ruby31/bin/ruby: bad interpreter: No such file or directory
gem install fastlane
/var/folders/69/qgnyrbkx23dbp0p6p_b6bc9m0000gn/T/bitrise289696288/step_src/._script_cont: /Users/vagrant/.asdf/installs/ruby/3.1.0/bin/gem: /Users/vagrant/ruby31/bin/ruby: bad interpreter: No such file or directory
gem
/Users/Vagrant/.asdf/lib/commands/command-exec.bash: /Users/Vagrant/.asdf/installs/ruby/3.1.0/bin/gem: /Users/vagrant/ruby31/bin/ruby: bad interpreter: No such file or directory
/Users/Vagrant/.asdf/lib/commands/command-exec.bash: line 28: /Users/Vagrant/.asdf/installs/ruby/3.1.0/bin/gem: Undefined error: 0

So I guess that It seems to be asdf install is not working. Do you guys have any ideas for thatā€¦?? Iā€™ve been spending for this so long time.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.