epicweb-dev / full-stack-foundations

Learn the foundational skills of building full stack web applications.

Home Page:https://epicweb.dev/workshops/full-stack-foundations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setup script fails on Linux distributions with package managers other than "apt"

benhsm opened this issue · comments

commented

I am using Arch Linux. After successfully installing dependencies, the setup script fails on my system after trying to install playwright. After a sudo prompt, the script errors out without providing much useful information:

[...]
    ✅  Success: Dependency Installation


    ▶️  Starting: Custom Setup
          Handling custom setup (if neccessary)
          Running the following command: npm run setup:custom --if-present

> setup:custom
> node ./scripts/setup-custom.js

🎭 installing playwright for testing... This may require sudo (or admin) privileges and may ask for your password.
[sudo] password for ben: 
    🚨  Failure: Custom Setup. Please review the messages above for information on how to troubleshoot and resolve this issue.

Digging into the custom-setup.js script, I see that the failing step is:

// [...]
console.log(
	'🎭 installing playwright for testing... This may require sudo (or admin) privileges and may ask for your password.',
)
const playwrightResult = await $({
	all: true,
})`npx playwright install chromium --with-deps`
if (playwrightResult.exitCode === 0) {
	console.log('✅ playwright installed')
} else {
	console.log(playwrightResult.all)
	throw new Error('❌  playwright install failed')
}
// [...]

Running the command manually, I get:

npx playwright install chromium --with-deps                                   
BEWARE: your OS is not officially supported by Playwright; installing dependencies for Ubuntu as a fallback.
Installing dependencies...
Switching to root user to install dependencies...
[sudo] password for ben: 
sh: line 1: apt-get: command not found
Failed to install browsers
Error: Installation process exited with code: 127

Workaround: running npx playwright install-deps --dry-run shows the apt-get command that would be used to install dependencies, and this can be used to find out what the dependencies actually are so that they can be installed manually, then npx playwright install chromium can be run without the --with-deps flag.

Possible remediations:

  • In the error case, the contents of the playwrightResult variable could be logged to the screen to at least let users know what's going on and point them to manual steps they can take.
  • Maybe using some sort of docker setup to run playwright could make things more seamless for people that run into this.

Thanks for posting this.

I'm surprised you didn't get any more helpful output. I do log the playwrightResult.all which should include all the output. And it should also log the playwright install failed message as well.

Hmmm... I'm not certain what to do about the core problem either. How did you manually install dependencies?

commented

Execa's $() appears to return a result only if a command is successful, and throws it otherwise, so the script terminates before playwrightResult gets logged.

Changing the flow control to "try-catch" instead of "if-else":

try {
    await $({
        all: true,
    })`npx playwright install chromium --with-deps`
	console.log('✅ playwright installed')
} catch (playwrightErrorResult) {
    console.log(playwrightErrorResult.all)
	throw new Error('❌  playwright install failed')
}

Gives me the desired error output:

# [...]
    ✅  Success: Dependency Installation


    ▶️  Starting: Custom Setup
          Handling custom setup (if neccessary)
          Running the following command: npm run setup:custom --if-present

> setup:custom
> node ./scripts/setup-custom.js

🎭 installing playwright for testing... This may require sudo (or admin) privileges and may ask for your password.
[sudo] password for ben: 
BEWARE: your OS is not officially supported by Playwright; installing dependencies for Ubuntu as a fallback.
Installing dependencies...
Switching to root user to install dependencies...
sh: line 1: apt-get: command not found
Failed to install browsers
Error: Installation process exited with code: 127
    🚨  Failure: Custom Setup. Please review the messages above for information on how to troubleshoot and resolve this issue.

The script simply fails just because playwright's dependency installation script invokes the Debian package manager, which doesn't exist on my system: sh: line 1: apt-get: command not found. I think I actually already had the relevant dependencies installed on my system as dependencies for other software. I'm not sure, but I think in this case the needed dependencies are just the same dependencies which are needed by Chromium, which I have installed. But other users of my distro have documented manually installing dependencies for playwright itself the various browsers in a clean install of the OS: microsoft/playwright#8100 (comment)

When I actually install playwright without --with-deps and run e2e tests in this repo or epic stack, I have had no problems, although I do get warnings from the CLI commands that my OS is not officially supported.

Thanks for that note! I've pushed a fix to the setup script. Will have to think about the best way to deal with this in the future.

I think this is the best we're going to do for now. Thanks again!