Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress fails to run npm postinstall #68

Open
MikeMcC399 opened this issue Jul 7, 2024 · 7 comments
Open

Cypress fails to run npm postinstall #68

MikeMcC399 opened this issue Jul 7, 2024 · 7 comments

Comments

@MikeMcC399
Copy link

MikeMcC399 commented Jul 7, 2024

Issue

Attempting to install the npm module cypress fails at the postinstall stage using npm.

npm info run [email protected] postinstall node_modules/cypress node index.js --exec install
npm info run [email protected] postinstall { code: 1, signal: null }

This issue does not occur if Node.js is not installed via snap, for instance via nvm.

Steps to reproduce

On Ubuntu:

mkdir cy-test
cd cy-test
git init
npm init -y
npm install cypress -D

Note: If Cypress has been previously fully installed, then you need to execute the following to delete the Cypress binary from its cache:

npx cypress cache clear

or

rm -rf ~/.cache/Cypress

Environment

Ubuntu 22.04.4 LTS
Node.js v20.14.0 8723 20/stable installed with snap

Continues to be reproducible with
node 20.15.1 8864 20/stable (bundled npm version 10.7.0)

Logs

Install

npm install cypress -D --ddd
...
npm info run [email protected] postinstall node_modules/cypress node index.js --exec install
npm info run [email protected] postinstall { code: 1, signal: null }
npm verbose stack Error: command failed
npm verbose stack     at ChildProcess.<anonymous> (/snap/node/8723/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:53:27)
npm verbose stack     at ChildProcess.emit (node:events:519:28)
npm verbose stack     at maybeClose (node:internal/child_process:1105:16)
npm verbose stack     at ChildProcess._handle.onexit (node:internal/child_process:305:5)
npm verbose pkgid [email protected]
npm verbose cwd /home/mike/github/cy-e2e-default
npm verbose Linux 6.5.0-41-generic
npm verbose node v20.14.0
npm verbose npm  v10.7.0
npm error code 1
npm error path /home/mike/github/cy-e2e-default/node_modules/cypress
npm error command failed
npm error command sh -c node index.js --exec install
npm verbose exit 1
npm verbose code 1

snap

$ snap list node
Name  Version  Rev   Tracking   Publisher  Notes
node  20.14.0  8723  20/stable  iojs✓      classic

Workaround

Workaround - split postinstall phase

npm install cypress -D --ignore-scripts
npx cypress install

npx cypress install is the equivalent of node ./node_modules/cypress/index.js --exec install

Workaround - install Node.js with nvm

Install Node.js on Ubuntu with nvm according to instructions on https://nodejs.org/en/download/package-manager

# installs nvm (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

# download and install Node.js (you may need to restart the terminal)
nvm install 20

# verifies the right Node.js version is in the environment
node -v # should print `v20.15.0`

# verifies the right NPM version is in the environment
npm -v # should print `10.7.0`
@MikeMcC399
Copy link
Author

I also found that running

npm install cypress --foreground-scripts

is successful, so it is something connected to running an npm lifecycle script in the background using node/npm from snap on Ubuntu.

@MikeMcC399
Copy link
Author

MikeMcC399 commented Jul 9, 2024

This issue only affects npm installed via snap node. Using Yarn installed via snap node works correctly.

The following sequence completes successfully:

yarn init -y
yarn add cypress -D
yarn cypress cache list

@MikeMcC399 MikeMcC399 changed the title Cypress fails to run postinstall Cypress fails to run npm postinstall Jul 9, 2024
@MikeMcC399
Copy link
Author

Also reproducible installing using npm with:

Ubuntu 24.04 LTS
node (22/stable) 22.4.1 from OpenJS Foundation (iojs✓) installed

@MikeMcC399
Copy link
Author

@rvagg

Will somebody be able to give some feedback on this issue? It may need a warning in the Cypress documentation, but I'd like to understand the root cause first before proposing a documentation update.

snap is one of the recommended node package managers on https://nodejs.org/en/download/package-manager/all

@rvagg
Copy link
Member

rvagg commented Jul 12, 2024

Sorry, I don't have clear advice for you on this one, snaps have trouble doing child process execs because they are already executed in constrained environments; I opt to not use node from a snap if I want to not bump into these problems. I wish I could get to the bottom of it and be able to either provide advice or fix something, but it's not obvious to me where to start digging and I don't have the time or reason to dig deeper, sorry.

@MikeMcC399
Copy link
Author

@rvagg

Thanks for your valuable feedback and my apologies for pinging you!

I'm going to assume that the problem is inherent to snap and I'll propose a documentation update to Cypress. I don't personally use snap as a package manager for node (I prefer n & nvm), but some other Cypress users have hit this issue and I'm trying to make sure that other users won't fall into the same trap.

@MikeMcC399
Copy link
Author

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

No branches or pull requests

2 participants