Skip to content

Commit 9ba96ad

Browse files
tido64react-native-bot
authored andcommitted
fix: fix @react-native-community/cli not being found in pnpm setups (#47304)
Summary: Fix `react-native-community/cli` not being found in pnpm setups ## Changelog: [GENERAL] [FIXED] - Fix `react-native-community/cli` not being found in pnpm setups Pull Request resolved: #47304 Test Plan: 1. Clone/check out this branch: microsoft/rnx-kit#3409 2. Run `yarn react-native config` Reviewed By: cortinico Differential Revision: D65209065 Pulled By: robhogan fbshipit-source-id: 2ceb73ad140b4afe193e879779c2d8a4b9adf3fc
1 parent e2b081e commit 9ba96ad

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/react-native/cli.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ const deprecated = () => {
2323
);
2424
};
2525

26+
function findCommunityCli(startDir = process.cwd()) {
27+
// With isolated node_modules (eg pnpm), we won't be able to find
28+
// `@react-native-community/cli` starting from the `react-native` directory.
29+
// Instead, we should use the project root, which we assume to be the cwd.
30+
const options = {paths: [startDir]};
31+
const rncli = require.resolve('@react-native-community/cli', options);
32+
return require(rncli);
33+
}
34+
2635
function isMissingCliDependency(error) {
2736
return (
2837
error.code === 'MODULE_NOT_FOUND' &&
@@ -217,7 +226,7 @@ async function main() {
217226
}
218227

219228
try {
220-
return require('@react-native-community/cli').run(name);
229+
return findCommunityCli().run(name);
221230
} catch (e) {
222231
if (isMissingCliDependency(e)) {
223232
warnWithExplicitDependency();
@@ -231,7 +240,7 @@ if (require.main === module) {
231240
main();
232241
} else {
233242
try {
234-
cli = require('@react-native-community/cli');
243+
cli = findCommunityCli();
235244
} catch (e) {
236245
// We silence @react-native-community/cli missing as it is no
237246
// longer a dependency

0 commit comments

Comments
 (0)