question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Cannot override `.npmrc` env var `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` from true to false

See original GitHub issue

Context:

  • Playwright Version: 1.5.1
  • Operating System: Linux for CI, Mac locally
  • Node.js version: 12.16.2
  • Browser: All

Describe the bug

The scenario we have is that we want to skip installing browsers by default in our ecosystem, but manually install browsers if a person is running playwright code locally or as part of the CI job that runs playwright code. As a result we set the following in our .npmrc:

playwright_skip_browser_download=1

Unfortunately, PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD="" yarn does not override this value (or any variation of this). I think this is because the concept of overriding env vars in the playwright repo is predicated on the idea of overriding falsey values with truthy values and not the other way around.

If we look at the code to skip the browser install:

  if (getFromENV('PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD')) {
    browserFetcher.logPolitely('Skipping browsers download because `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` env variable is set');
    return false;
  }
``
We need `getFromENV('PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD')` to return a falsey value to get past this block. When we look at the code from [`getFromEnv`](https://github.com/microsoft/playwright/blob/master/src/utils/utils.ts#L98-L103):

export function getFromENV(name: string) { let value = process.env[name]; value = value || process.env[npm_config_${name.toLowerCase()}]; value = value || process.env[npm_package_config_${name.toLowerCase()}]; return value; }

we see that it's impossible to override the truthy value of `process.env.npm_config_playwright_skip_browser_download` with a falsey value no matter what we do. I think changes the `||` operators to `??` might fix the issue.

Additionally, it might be worth being explicit about possible values for `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD`, cast them from a string to a number (`"0"` is true after all, while `0` is not) and do a !! in the check. 

I'll put up a corresponding PR for your review.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
pavelfeldmancommented, Oct 23, 2020

Btw, for installing the browsers, you could also run npx playwright-cli

0reactions
majapwcommented, Oct 23, 2020

Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - .npmrc config file not reading environment variable to ...
I figured out the error in my assumption, and have come to a solution. tl;dr - create shell-based persistant environment variables, ...
Read more >
config | npm Docs
Any environment variables that start with npm_config_ will be interpreted as a ... Run npm config ls -l to see a set of...
Read more >
.npmrc | pnpm
pnpm gets its configuration from the command line, environment variables, and. ... When true , all dependencies are hoisted to node_modules/.pnpm .
Read more >
Configuration | NestJS - A progressive Node.js framework
Externally defined environment variables are visible inside Node.js through the process.env global. We could try to solve the problem of multiple environments ...
Read more >
Configure and use npm with CodeArtifact - AWS Documentation
For npm 6 and lower: Adds "always-auth=true" so the authorization token is ... For information on configuring environment variables on a Windows machine, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found