diff --git a/packages/create-react-app/createReactApp.js b/packages/create-react-app/createReactApp.js index 132d55a8373..8de482657d8 100755 --- a/packages/create-react-app/createReactApp.js +++ b/packages/create-react-app/createReactApp.js @@ -242,7 +242,22 @@ function createApp(name, verbose, version, useNpm, usePnp, template) { // Fall back to latest supported react-scripts for npm 3 version = 'react-scripts@0.9.x'; } + } else if (usePnp) { + const yarnInfo = checkYarnVersion(); + if (!yarnInfo.hasMinYarnPnp) { + if (yarnInfo.yarnVersion) { + chalk.yellow( + `You are using Yarn ${ + yarnInfo.yarnVersion + } together with the --use-pnp flag, but Plug'n'Play is only supported starting from the 1.12 release.\n\n` + + `Please update to Yarn 1.12 or higher for a better, fully supported experience.\n` + ); + } + // 1.11 had an issue with webpack-dev-middleware, so better not use PnP with it (never reached stable, but still) + usePnp = false; + } } + run( root, appName, @@ -565,6 +580,23 @@ function checkNpmVersion() { }; } +function checkYarnVersion() { + let hasMinYarnPnp = false; + let yarnVersion = null; + try { + yarnVersion = execSync('yarnpkg --version') + .toString() + .trim(); + hasMinYarnPnp = semver.gte(yarnVersion, '1.12.0'); + } catch (err) { + // ignore + } + return { + hasMinYarnPnp: hasMinYarnPnp, + yarnVersion: yarnVersion, + }; +} + function checkNodeVersion(packageName) { const packageJsonPath = path.resolve( process.cwd(),