npm/npx

[BUG] Npx doesn't execute my scoped package and opens its bin file in my editor

Closed this issue · 4 comments

What / Why

I freshly published a binary tool to help me with my projects (https://www.npmjs.com/package/@telokys/easy-typescript).
The code source can be found there if need be.
I expected to be able to run npx @telokys/easy-typescript in order to easily run my bin without even installing it.
Instead of running my script, npx opens the build/src/bin.js file inside my VSCode without executing it.
It stills prints npx: installed 12 in 4.738s but doesn't execute anything.
I tried using npx -p @telokys/easy-typescript easy-typescript but the exact same behavior occurred.

npx works fine for anything else and I just updated it (using npm i -g npm@latest) to version 6.14.2.

As a side note, I also get an annoying error about rimraf:

npx: installed 12 in 4.738s

 C:\Users\Telokis\AppData\Roaming\npm\node_modules\npm\node_modules\rimraf\rimraf.js:313
        throw er
        ^

Error: ENOTEMPTY: directory not empty, rmdir 'C:\Users\Telokis\AppData\Roaming\npm-cache\_npx\1176\node_modules\@telokys\easy-typescript\build'
    at Object.rmdirSync (fs.js:769:3)
    at rmkidsSync (C:\Users\Telokis\AppData\Roaming\npm\node_modules\npm\node_modules\rimraf\rimraf.js:356:25)
    at rmdirSync (C:\Users\Telokis\AppData\Roaming\npm\node_modules\npm\node_modules\rimraf\rimraf.js:334:7)
    at rimrafSync (C:\Users\Telokis\AppData\Roaming\npm\node_modules\npm\node_modules\rimraf\rimraf.js:304:9)
    at C:\Users\Telokis\AppData\Roaming\npm\node_modules\npm\node_modules\rimraf\rimraf.js:342:5
    at Array.forEach (<anonymous>)
    at rmkidsSync (C:\Users\Telokis\AppData\Roaming\npm\node_modules\npm\node_modules\rimraf\rimraf.js:341:26)
    at rmdirSync (C:\Users\Telokis\AppData\Roaming\npm\node_modules\npm\node_modules\rimraf\rimraf.js:334:7)
    at rimrafSync (C:\Users\Telokis\AppData\Roaming\npm\node_modules\npm\node_modules\rimraf\rimraf.js:304:9)
    at C:\Users\Telokis\AppData\Roaming\npm\node_modules\npm\node_modules\rimraf\rimraf.js:342:5 {
  errno: -4051,
  syscall: 'rmdir',
  code: 'ENOTEMPTY',
  path: 'C:\\Users\\Telokis\\AppData\\Roaming\\npm-cache\\_npx\\1176\\node_modules\\@telokys\\easy-typescript\\build'
}

Perhaps that file doesn't have +x set on it? bin files need to be executable.

Oh I need to +x it before publishing to npm?

You should anyways, for explicitness, altho i think npm will fix that for you when it's installed; but if you want it ran locally then you must.

Ok this was a very stupid issue on my end: I forgot to add a shebang to my bin file...