Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: warn against using globally scoped install (#13196)

Ross Wollman42798b585799
diff --git a/packages/playwright-core/src/cli/cli.ts b/packages/playwright-core/src/cli/cli.ts
index 552bd8fe98..0759091a1e 100755
--- a/packages/playwright-core/src/cli/cli.ts
+++ b/packages/playwright-core/src/cli/cli.ts
@@ -32,7 +32,7 @@ import { BrowserType } from '../client/browserType';
import { BrowserContextOptions, LaunchOptions } from '../client/types';
import { spawn } from 'child_process';
import { registry, Executable } from '../utils/registry';
-import { spawnAsync, getPlaywrightVersion } from '../utils/utils';
+import { spawnAsync, getPlaywrightVersion, wrapInASCIIBox } from '../utils/utils';
import { writeDockerVersion } from '../utils/dependencies';
import { launchGridAgent } from '../grid/gridAgent';
import { GridServer, GridFactory } from '../grid/gridServer';
@@ -115,6 +115,27 @@ program
.option('--with-deps', 'install system dependencies for browsers')
.option('--force', 'force reinstall of stable browser channels')
.action(async function(args: string[], options: { withDeps?: boolean, force?: boolean }) {
+ const isLikelyNpxGlobal = process.argv.length >= 2 && process.argv[1].includes('_npx');
+ if (isLikelyNpxGlobal) {
+ console.error(wrapInASCIIBox([
+ `WARNING: It looks like you are running 'npx playwright install' without first`,
+ `installing your project's dependencies.`,
+ ``,
+ `To avoid unexpected behavior, please install your dependencies first, and`,
+ `then run Playwright's install command:`,
+ ``,
+ ` npm install`,
+ ` npx playwright install`,
+ ``,
+ `If your project does not yet depend on Playwright, first install the`,
+ `applicable npm package (most commonly @playwright/test), and`,
+ `then run Playwright's install command to download the browsers:`,
+ ``,
+ ` npm install @playwright/test`,
+ ` npx playwright install`,
+ ``,
+ ].join('\n'), 1));
+ }
try {
if (!args.length) {
const executables = registry.defaultExecutables();