npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.33k stars 3.07k forks source link

[BUG] npx crashes when mixing implicit/explicit modules in -p #3668

Closed nikolaik closed 2 years ago

nikolaik commented 3 years ago

Is there an existing issue for this?

Current Behavior

Run the following npx command in a directory that has an existing node_modules with one of the modules already installed. When mixing implict and specific like below, npx crashes when it tries to tread undefined as a string.

$ npx -p gitmoji-cli@1.0.0 -p @babel/core gitmoji -l
npm ERR! Cannot read property 'replace' of undefined

Here is the stack trace from the debug log:

32 verbose stack TypeError: Cannot read property 'replace' of undefined
32 verbose stack     at .nvm/versions/node/v14.16.0/lib/node_modules/npm/node_modules/libnpmexec/lib/index.js:163:47
32 verbose stack     at Array.map (<anonymous>)
32 verbose stack     at exec (.nvm/versions/node/v14.16.0/lib/node_modules/npm/node_modules/libnpmexec/lib/index.js:163:31)

Not sure if it crashes because of the missing version specifier @babel/core when it already has a fixed version in package.json or something else.

Expected Behavior

Expect it to prompt for installation (the first time it is run):

$ npx -p gitmoji-cli@1.0.0 -p @babel/core@7 gitmoji -l
Need to install the following packages:
  @babel/core@7
  gitmoji-cli@1.0.0
Ok to proceed? (y) 

Steps To Reproduce

# create a new dir with an empty package.json
mkdir fresh-dir && cd fresh-dir && npm init -y
npm i @babel/core
npx -p gitmoji-cli@1.0.0 -p @babel/core gitmoji -l

Environment

nlf commented 2 years ago

4643 fixes this issue /cc @ruyadorno

ruyadorno commented 2 years ago

moved the bit that fixes this issue to #4777