Skip to content
This repository has been archived by the owner on Jun 30, 2024. It is now read-only.

./node_modules/.bin/npx not found :( #1

Closed
zkat opened this issue Jul 12, 2017 · 3 comments
Closed

./node_modules/.bin/npx not found :( #1

zkat opened this issue Jul 12, 2017 · 3 comments

Comments

@zkat
Copy link

zkat commented Jul 12, 2017

➜ npx dist-upgrade --help
npx: installed 508 in 8.375s
/Users/zkat/.npm/_npx/67934/bin/dist-upgrade: line 3: ./node_modules/.bin/npx: No such file or directory

Unfortunately, there's no easy, surefire way to get the path to a dep's binary from a shell script. :\

@zkat zkat changed the title :( ./node_modules/.bin/npx not found :( Jul 12, 2017
@zacanger
Copy link
Owner

zacanger commented Jul 12, 2017

Thanks for pointing that out! I believe something like this would handle a most cases, but it's totally possible I'm missing something important. Do you have any thoughts on that?

#!/bin/sh

WHICH=`which npx`
NPMBIN=`npm bin`/npx
NPX=${WHICH:-$NPMBIN}

$NPX n latest && npm i -g npm@next

@zkat
Copy link
Author

zkat commented Jul 13, 2017

This still won't run the npx included with dist-upgrade.

The issue here is that your shell script can't figure out where it is -- it runs from pwd. Since the bash script is symlinked, it won't know where your original node_modules is.

Something like this will do the trick though:

#!/usr/bin/env node

const cp = require('child_process')
const path = require('path')

const NPX_BIN = path.join(__dirname, 'node_modules', '.bin', 'npx')
cp.spawn(`${NPX_BIN} n latest && npm i -g npm@next`, [], {
  stdio: 'inherit',
  shell: true
})

'cause __dirname works right.

@zacanger
Copy link
Owner

Thanks so much! I feel like a bit of a ditz for not realising that. Fixed in 0.2.0.

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

Successfully merging a pull request may close this issue.

2 participants