diff --git a/index.js b/index.js index 070f75e..e65cd72 100644 --- a/index.js +++ b/index.js @@ -86,6 +86,9 @@ function npx (argv) { if (process.platform === 'win32') { bins = bins.filter(b => b !== 'etc' && b !== 'node_modules') } + if (bins.length < 1) { + throw new Error(Y()`command not found: ${argv.command}`) + } const cmd = new RegExp(`^${argv.command}(?:\\.cmd)?$`, 'i') const matching = bins.find(b => b.match(cmd)) return path.resolve(results.bin, bins[matching] || bins[0]) diff --git a/test/index.js b/test/index.js index 28ad779..1dcaf6b 100644 --- a/test/index.js +++ b/test/index.js @@ -281,3 +281,16 @@ test('noisy npx with --quiet arg on windows', { t.end() }) }) + +test('nice error message when no binaries on windows', { + skip: !isWindows && 'Only on Windows is the error message inscrutable' +}, t => { + return child.spawn('node', [ + NPX_ESC, '0' + ], {stdio: 'pipe'}).then(res => { + throw new Error('Should not have succeeded') + }, err => { + t.equal(err.stderr.split('\n')[1].trim(), 'command not found: 0') + t.end() + }) +})