Cli: [BUG] npx behavior in CI environments

Created on 9 Oct 2020  ·  14Comments  ·  Source: npm/cli

This isn't really a bug, but raising it to discuss the potential impact of changes to npx in CI environments.

Current Behavior:

npx mocha
Need to install the following packages:
 mocha
Ok to proceed? (y)

npx -y mocha works to get the automatic install behaviour, but that would require users to update their CI scripts.

Also, npx -y mocha errors in npm@6 with:

npx -y mocha
ERROR: You must supply a command.
Execute binaries from npm packages.
  npx [options] <command>[@version] [command-arg]...

I think that would complicate the logic required in CI scripts when running across multiple Node.js/npm versions.

_Just using Mocha as an example. In Node.js, we use npx in our GH Actions configuration, which I suspect would be broken when GH Actions updates to use a version of Node.js containing npm@7._

Expected Behavior:

  • Unsure, but curious if there could be a workaround that removes the need for users to edit their scripts.

Steps To Reproduce:

  • npx <module> in a CI enironment.

Environment:

  • All CI environments

/cc @MylesBorins @richardlau

Bug Release 7.x

Most helpful comment

we published 7.0.6 today that should hopefully resolve this. we now skip the prompt entirely if you appear to be running in a CI environment.

let us know if you continue to have issues!

All 14 comments

@ruyadorno mentioned in the slack conversation that this was an intentional breaking change, could someone link to the context for that decision?

hi @BethGriggs thanks for letting us know 😄

It's worth mentioning that for non-interactive terminals we are going to patch (ref #1936) npx to only WARN instead of throwing so any combination of Unix pipelines would also avoid the prompt/confirmation:

  • npx mocha < /dev/null

as also mentioned in the slack channel: npm_config_yes=true npx mocha is the working npm6-7 compat version of it

we published 7.0.0-rc.4 today that skips the prompt, but prints a warning, when run in a non-interactive environment. that way you're still alerted that something is being installed but we do not break in CI environments.

for interactive environments the above workaround should do the trick.

can you let us know if this resolves your issue @BethGriggs?

we published 7.0.0-rc.4 today that skips the prompt, but prints a warning, when run in a non-interactive environment. that way you're still alerted that something is being installed but we do not break in CI environments.

for interactive environments the above workaround should do the trick.

can you let us know if this resolves your issue @BethGriggs?

root@localhost ~# npm install -g [email protected]
npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module 'agentkeepalive'
npm ERR! Require stack:
npm ERR! - /usr/local/lib/node_modules/npm/node_modules/make-fetch-happen/agent.js
npm ERR! - /usr/local/lib/node_modules/npm/node_modules/make-fetch-happen/index.js
npm ERR! - /usr/local/lib/node_modules/npm/node_modules/npm-registry-fetch/index.js
npm ERR! - /usr/local/lib/node_modules/npm/lib/utils/metrics.js
npm ERR! - /usr/local/lib/node_modules/npm/lib/npm.js
npm ERR! - /usr/local/lib/node_modules/npm/lib/cli.js
npm ERR! - /usr/local/lib/node_modules/npm/bin/npm-cli.js

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-10-10T03_17_28_890Z-debug.log

can you let us know if this resolves your issue @BethGriggs?

I think the concern has been addressed to reduce the impact in CI environments, thanks!

closing since the original issue is resolved.

@gengjiawen if you're able to reproduce the problem you had updating, please do open another issue and we can discuss it there

FWIW, I bumped into this in TravisCI: https://travis-ci.com/github/kentcdodds/advanced-react-hooks/builds/191260988

image

I think that @BethGriggs' original concern is still an issue 😬

hmmm 🤔 maybe we should also check for the environment using @npmcli/ci-detect on top of checking for process.stdin.isTTY @nlf ?

Hitting this too, it broken all our CI scripts... Why did you introduce a breaking change in a minor/patch release?

For anyone having this issue on Circle CI, you can set a global environment variable to set the npm_config_yes variable to true to all your jobs

@FezVrasta the change came in the 7.0.0 Semver-Major change. We thought we fixed the CI issue by checking for TTY, but it seems there are edge cases we missed. Looks like #2047 is open to hopefully fix this for more CI environments

we published 7.0.6 today that should hopefully resolve this. we now skip the prompt entirely if you appear to be running in a CI environment.

let us know if you continue to have issues!

Works for us now: https://github.com/testing-library/react-testing-library/pull/809/files

Thank you for the quick fix!

Question: when npx7 prompts and then user installs the missing package,

  1. where is the package stored? Apparently it's not installed as global npm package.
  2. how to force npx makes to check and download latest version of "makes"? We got trouble that npx makes is trapped with local installed old version of "makes".
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jaydenseric picture jaydenseric  ·  3Comments

DullReferenceException picture DullReferenceException  ·  4Comments

goldingdamien picture goldingdamien  ·  4Comments

zypA13510 picture zypA13510  ·  4Comments

darcyclarke picture darcyclarke  ·  4Comments