asdf-nodejs icon indicating copy to clipboard operation
asdf-nodejs copied to clipboard

npx or similar commands not working as expected?

Open jfrux opened this issue 4 years ago • 13 comments

Any tips on how to handle the below issues?

$> asdf --version
v0.7.4
$> asdf which npx
/Users/joshua/.asdf/installs/nodejs/11.10.1/.npm/bin/npx
$> npx

ERROR: You must supply a command.

Execute binaries from npm packages.

  npx [options] <command>[@version] [command-arg]...

  npx [options] [-p|--package <package>]... <command> [command-arg]...

  npx [options] -c '<command-string>'

  npx --shell-auto-fallback [shell]


Options:
  --package, -p          Package to be installed.                       [string]
  --cache                Location of the npm cache.                     [string]
  --always-spawn         Always spawn a child process to execute the command.
                                                                       [boolean]
  --no-install           Skip installation if a package is missing.    [boolean]
  --userconfig           Path to user npmrc.                            [string]
  --call, -c             Execute string as if inside `npm run-script`.  [string]
  --shell, -s            Shell to execute the command with, if any.
                                                       [string] [default: false]
  --shell-auto-fallback  Generate shell code to use npx as the "command not
                         found" fallback.
                                   [string] [choices: "", "bash", "fish", "zsh"]
  --ignore-existing      Ignores existing binaries in $PATH, or in the local
                         project. This forces npx to do a temporary install and
                         use the latest version.                       [boolean]
  --quiet, -q            Suppress output from npx itself. Subcommands will not
                         be affected.                                  [boolean]
  --npm                  npm binary to use for internal operations.
                                                              [string] [default:
  "/Users/joshua/.asdf/installs/nodejs/11.10.1/.npm/lib/node_modules/npx/node_mo
                                                      dules/npm/bin/npm-cli.js"]
  --node-arg, -n         Extra node argument when calling a node binary.[string]
  --version, -v          Show version number                           [boolean]
  --help, -h             Show help                                     [boolean]

For the full documentation, see the manual page for npx(1).

$> npx create-react-app
asdf: No version set for command create-react-app
you might want to add one of the following in your .tool-versions file:

nodejs 8.3.0
nodejs 11.6.0
$> which npx
/Users/joshua/.asdf/shims/npx

jfrux avatar Sep 11 '19 13:09 jfrux

It's even weird because if I run this...

$> /Users/joshua/.asdf/installs/nodejs/11.10.1/lib/node_modules/npm/bin/npx-cli.js create-react-app
asdf: No version set for command create-react-app
you might want to add one of the following in your .tool-versions file:

nodejs 8.3.0
nodejs 11.6.0

I get the same thing... :-/

jfrux avatar Sep 11 '19 13:09 jfrux

I've tried to install fresh versions of nodejs with asdf, still no go... wondering if it's yarn somehow interfering?

jfrux avatar Sep 11 '19 13:09 jfrux

Sorry for the late response. Very strange. What is the output of type -a npx? What is the output of type -a create-react-app? I suspect npx may not actually be the npx from asdf.

Stratus3D avatar Dec 19 '19 19:12 Stratus3D

@Stratus3D I mentioned having a similar problem in #517 with this output:

$ cat .tool-versions
nodejs 10.17.0
$ npx react-native init ReactNativeApp
asdf: No version set for command react-native
you might want to add one of the following in your .tool-versions file:

nodejs 10.7.0
$ asdf --version
v0.7.6-6207e42

Here's some more context from that directory:

$ type -a npx
npx is /Users/logandonoughe/.asdf/shims/npx
npx is /usr/local/bin/npx
$ type -a react-native
react-native not found

LDonoughe avatar Jan 08 '20 18:01 LDonoughe

Similar issue. Updated to latest, re-shimmed:

Parkers-MacBook-Pro:projects parkerwightman$ asdf update --head
From https://github.com/asdf-vm/asdf
 * branch            master     -> FETCH_HEAD
Previous HEAD position was 6207e42 Update version to 0.7.6
Branch 'master' set up to track remote branch 'master' from 'origin'.
Switched to a new branch 'master'
HEAD is now at 51104c9 Merge pull request #647 from jsejcksn/master
Updated asdf to latest on the master branch
Parkers-MacBook-Pro:projects parkerwightman$ asdf plugin update nodejs
Updating nodejs...
Already on 'master'
Your branch is up to date with 'origin/master'.
Parkers-MacBook-Pro:projects parkerwightman$ npx react-native init UniteMobile
asdf: No preset version installed for command react-native
Please install the missing version by running one of the following:

asdf install nodejs 12.16.0

or add one of the following in your .tool-versions file:

nodejs 8.16.2
Parkers-MacBook-Pro:projects parkerwightman$ asdf list
elixir
  1.6.4-otp-20
  1.8.2-otp-20
erlang
  20.3
nodejs
  12.16.0
  8.11.3
  8.16.2
ruby
  2.4.2
  2.5.1
rust
  1.30.1
Parkers-MacBook-Pro:projects parkerwightman$ asdf install nodejs 12.16.0
nodejs 12.16.0 is already installed
Parkers-MacBook-Pro:projects parkerwightman$ which npx
/Users/parkerwightman/.asdf/shims/npx
Parkers-MacBook-Pro:projects parkerwightman$ type -a npx
npx is /Users/parkerwightman/.asdf/shims/npx
npx is /usr/local/bin/npx
Parkers-MacBook-Pro:projects parkerwightman$

Invoking npx executes find (shows help text), but breaks when invoking npx react-native ...

FWIW, changing the nodejs version to 8.16.2 does run the command correctly.

pwightman avatar Feb 17 '20 16:02 pwightman

I think I figured out my problem. I was previously using 8.16.2 as my global version, and had [email protected] installed as a global package. Switching back to 8.16.2, uninstalling the package, switching back to 12.16.0, and reshimming fixed the issue.

I'm not sure if a bug still exists within asdf for failing here, given that I was not invoking the react-native executable, but rather passing the string react-native as an argument to npx, but maybe npx is invoking it under-the-hood, not sure how it all works.

My console output in case it's helpful:

Parkers-MacBook-Pro:projects parkerwightman$ asdf global nodejs 8.16.2
Parkers-MacBook-Pro:projects parkerwightman$ npm list -g --depth 0
/Users/parkerwightman/.asdf/installs/nodejs/8.16.2/.npm/lib
└── [email protected]

Parkers-MacBook-Pro:projects parkerwightman$ npm uninstall -g react-native-cli
removed 50 packages in 0.382s
Parkers-MacBook-Pro:projects parkerwightman$ npm list -g --depth 0
/Users/parkerwightman/.asdf/installs/nodejs/8.16.2/.npm/lib
└── (empty)

Parkers-MacBook-Pro:projects parkerwightman$ asdf global nodejs 12.16.0
Parkers-MacBook-Pro:projects parkerwightman$ asdf reshim
Parkers-MacBook-Pro:projects parkerwightman$ npx react-native init UniteMobile

               ######                ######
             ###     ####        ####     ###
            ##          ###    ###          ##
            ##             ####             ##
            ##             ####             ##
            ##           ##    ##           ##
            ##         ###      ###         ##
             ##  ########################  ##
          ######    ###            ###    ######
      ###     ##    ##              ##    ##     ###
   ###         ## ###      ####      ### ##         ###
  ##           ####      ########      ####           ##
 ##             ###     ##########     ###             ##
  ##           ####      ########      ####           ##
   ###         ## ###      ####      ### ##         ###
      ###     ##    ##              ##    ##     ###
          ######    ###            ###    ######
             ##  ########################  ##
            ##         ###      ###         ##
            ##           ##    ##           ##
            ##             ####             ##
            ##             ####             ##
            ##          ###    ###          ##
             ###     ####        ####     ###
               ######                ######


                  Welcome to React Native!
                 Learn once, write anywhere

pwightman avatar Feb 17 '20 16:02 pwightman

I get this issue with yarn on each new version install. For example after installing 12.3.1 and trying to run yarn:

$ yarn
asdf: No version set for command yarn
you might want to add one of the following in your .tool-versions file:

nodejs 13.9.0
nodejs 10.13.0
nodejs 10.19.0

What I notice here:

  • 12.3.1 is not listed here but is listed by asdf list nodejs
  • 12.3.1 is in .nvmrc and I have also added a .tool-versions file as mentioned above
  • i have a .default-npm-packages file which contains a single line yarn
  • which yarn points to an asdf shim
  • the issue is fixed if i run npm i -g yarn again.

erikdstock avatar Feb 26 '20 17:02 erikdstock

An improved error message could help. I've seen this error a fair few times, and the solution it suggests has never been the proper solution. Something along the lines of:

$ yarn
asdf: No version set for command yarn

You may be trying to run a global executable installed under a different version of nodejs.

Try re-installing the executable, or add one of the following versions of nodejs 
(which contains the executable) to your .tool-versions file:

....

I don't understand the underlying mechanics well enough to know if that's a good/accurate message...I just know the current message has never been the correct solution for me.

pwightman avatar Feb 26 '20 18:02 pwightman

Any update here? Referring to my comment above, this does NOT seem to work for npx which makes asdf basically broken for me.

erikdstock avatar Jun 11 '20 19:06 erikdstock

For any future visitors, I was able to work around the issue by passing --ignore-existing to npx, like:

npx --ignore-existing create-react-app my-app

ciaran avatar Sep 19 '20 14:09 ciaran

My issue was related to the fact that I had create-react-app installed for a previous version of nodejs and not the one that was set as the current local/global version. Manually installing create-react-app for the desired version did the trick. This is likely why the --ignore-existing suggestion above could help folks.

gitteri avatar Aug 02 '21 02:08 gitteri

$ npx --ignore-existing create-react-app my-app
npx: the --ignore-existing argument has been removed.
$ asdf current nodejs
nodejs          17.9.0          ASDF_NODEJS_VERSION environment variable

DanLipsitt avatar Apr 13 '22 20:04 DanLipsitt

The npm cache seems to be involved.

$ npm cache ls create-react-app
make-fetch-happen:request-cache:https://registry.npmjs.org/create-react-app
make-fetch-happen:request-cache:https://registry.npmjs.org/create-react-app/-/create-react-app-4.0.3.tgz
make-fetch-happen:request-cache:https://registry.npmjs.org/create-react-app/-/create-react-app-5.0.1.tgz

The following did not help:

$ npm cache clean 'make-fetch-happen:request-cache:https://registry.npmjs.org/create-react-app'
Deleted: make-fetch-happen:request-cache:https://registry.npmjs.org/create-react-app
$ npm cache clean 'make-fetch-happen:request-cache:https://registry.npmjs.org/create-react-app/-/create-react-app-4.0.3.tgz'
Deleted: make-fetch-happen:request-cache:https://registry.npmjs.org/create-react-app/-/create-react-app-4.0.3.tgz

but using an empty cache did:

$  npx --cache /tmp/empty-cache create-react-app my-app

DanLipsitt avatar Apr 13 '22 23:04 DanLipsitt