Skip to content

Commit f433381

Browse files
feat: always use nodeLinker: node-modules (#2135)
1 parent 9c52009 commit f433381

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/cli/src/commands/init/template.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import copyFiles from '../../tools/copyFiles';
66
import replacePathSepForRegex from '../../tools/replacePathSepForRegex';
77
import fs from 'fs';
88
import chalk from 'chalk';
9+
import {getYarnVersionIfAvailable} from '../../tools/yarn';
10+
import {executeCommand} from '../../tools/packageManager';
911

1012
export type TemplateConfig = {
1113
placeholderName: string;
@@ -27,6 +29,15 @@ export async function installTemplatePackage(
2729
root,
2830
});
2931

32+
// React Native doesn't support PnP, so we need to set nodeLinker to node-modules. Read more here: https://github.com/react-native-community/cli/issues/27#issuecomment-1772626767
33+
34+
if (packageManager === 'yarn' && getYarnVersionIfAvailable() !== null) {
35+
executeCommand('yarn', ['config', 'set', 'nodeLinker', 'node-modules'], {
36+
root,
37+
silent: true,
38+
});
39+
}
40+
3041
return PackageManager.install([templateName], {
3142
packageManager,
3243
silent: true,

packages/cli/src/tools/packageManager.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,13 @@ function configurePackageManager(
6565
return executeCommand(pm, args, options);
6666
}
6767

68-
function executeCommand(
68+
export function executeCommand(
6969
command: string,
7070
args: Array<string>,
71-
options: Options,
71+
options: {
72+
root: string;
73+
silent?: boolean;
74+
},
7275
) {
7376
return execa(command, args, {
7477
stdio: options.silent && !logger.isVerbose() ? 'pipe' : 'inherit',

0 commit comments

Comments
 (0)