Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1f81469

Browse files
authored
Fix --use-pnp for Yarn 2 (#8460)
1 parent 408c065 commit 1f81469

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

packages/create-react-app/createReactApp.js

+18-4
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,26 @@ function createApp(
261261
}
262262
} else if (usePnp) {
263263
const yarnInfo = checkYarnVersion();
264-
if (!yarnInfo.hasMinYarnPnp) {
265-
if (yarnInfo.yarnVersion) {
264+
if (yarnInfo.yarnVersion) {
265+
if (!yarnInfo.hasMinYarnPnp) {
266266
console.log(
267267
chalk.yellow(
268268
`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` +
269269
`Please update to Yarn 1.12 or higher for a better, fully supported experience.\n`
270270
)
271271
);
272+
// 1.11 had an issue with webpack-dev-middleware, so better not use PnP with it (never reached stable, but still)
273+
usePnp = false;
274+
}
275+
if (!yarnInfo.hasMaxYarnPnp) {
276+
console.log(
277+
chalk.yellow(
278+
'The --use-pnp flag is no longer necessary with yarn 2 and will be deprecated and removed in a future release.\n'
279+
)
280+
);
281+
// 2 supports PnP by default and breaks when trying to use the flag
282+
usePnp = false;
272283
}
273-
// 1.11 had an issue with webpack-dev-middleware, so better not use PnP with it (never reached stable, but still)
274-
usePnp = false;
275284
}
276285
}
277286

@@ -775,14 +784,17 @@ function checkNpmVersion() {
775784

776785
function checkYarnVersion() {
777786
const minYarnPnp = '1.12.0';
787+
const maxYarnPnp = '2.0.0';
778788
let hasMinYarnPnp = false;
789+
let hasMaxYarnPnp = false;
779790
let yarnVersion = null;
780791
try {
781792
yarnVersion = execSync('yarnpkg --version')
782793
.toString()
783794
.trim();
784795
if (semver.valid(yarnVersion)) {
785796
hasMinYarnPnp = semver.gte(yarnVersion, minYarnPnp);
797+
hasMaxYarnPnp = semver.lt(yarnVersion, maxYarnPnp);
786798
} else {
787799
// Handle non-semver compliant yarn version strings, which yarn currently
788800
// uses for nightly builds. The regex truncates anything after the first
@@ -791,13 +803,15 @@ function checkYarnVersion() {
791803
if (trimmedYarnVersionMatch) {
792804
const trimmedYarnVersion = trimmedYarnVersionMatch.pop();
793805
hasMinYarnPnp = semver.gte(trimmedYarnVersion, minYarnPnp);
806+
hasMaxYarnPnp = semver.lt(trimmedYarnVersion, maxYarnPnp);
794807
}
795808
}
796809
} catch (err) {
797810
// ignore
798811
}
799812
return {
800813
hasMinYarnPnp: hasMinYarnPnp,
814+
hasMaxYarnPnp: hasMaxYarnPnp,
801815
yarnVersion: yarnVersion,
802816
};
803817
}

0 commit comments

Comments
 (0)