Skip to content

Commit d6682c8

Browse files
arcanisgaearon
authored andcommitted
Adds a version check when using --use-pnp (facebook#5269)
1 parent b41e696 commit d6682c8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

packages/create-react-app/createReactApp.js

+32
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,22 @@ function createApp(name, verbose, version, useNpm, usePnp, template) {
242242
// Fall back to latest supported react-scripts for npm 3
243243
version = '[email protected]';
244244
}
245+
} else if (usePnp) {
246+
const yarnInfo = checkYarnVersion();
247+
if (!yarnInfo.hasMinYarnPnp) {
248+
if (yarnInfo.yarnVersion) {
249+
chalk.yellow(
250+
`You are using Yarn ${
251+
yarnInfo.yarnVersion
252+
} together with the --use-pnp flag, but Plug'n'Play is only supported starting from the 1.12 release.\n\n` +
253+
`Please update to Yarn 1.12 or higher for a better, fully supported experience.\n`
254+
);
255+
}
256+
// 1.11 had an issue with webpack-dev-middleware, so better not use PnP with it (never reached stable, but still)
257+
usePnp = false;
258+
}
245259
}
260+
246261
run(
247262
root,
248263
appName,
@@ -565,6 +580,23 @@ function checkNpmVersion() {
565580
};
566581
}
567582

583+
function checkYarnVersion() {
584+
let hasMinYarnPnp = false;
585+
let yarnVersion = null;
586+
try {
587+
yarnVersion = execSync('yarnpkg --version')
588+
.toString()
589+
.trim();
590+
hasMinYarnPnp = semver.gte(yarnVersion, '1.12.0');
591+
} catch (err) {
592+
// ignore
593+
}
594+
return {
595+
hasMinYarnPnp: hasMinYarnPnp,
596+
yarnVersion: yarnVersion,
597+
};
598+
}
599+
568600
function checkNodeVersion(packageName) {
569601
const packageJsonPath = path.resolve(
570602
process.cwd(),

0 commit comments

Comments
 (0)