diff --git a/common/changes/@microsoft/rush/fix-rush-sdk-loading-issue_2023-03-30-19-19.json b/common/changes/@microsoft/rush/fix-rush-sdk-loading-issue_2023-03-30-19-19.json new file mode 100644 index 00000000000..35bc3cd862a --- /dev/null +++ b/common/changes/@microsoft/rush/fix-rush-sdk-loading-issue_2023-03-30-19-19.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "Fix an issue where rush-sdk sometimes failed to load if the globally installed Rush version was older than rushVersion in rush.json (GitHub #4039)", + "type": "none" + } + ], + "packageName": "@microsoft/rush" +} \ No newline at end of file diff --git a/libraries/rush-lib/src/utilities/SetRushLibPath.ts b/libraries/rush-lib/src/utilities/SetRushLibPath.ts index ec18843e67b..236a8b89f25 100644 --- a/libraries/rush-lib/src/utilities/SetRushLibPath.ts +++ b/libraries/rush-lib/src/utilities/SetRushLibPath.ts @@ -2,11 +2,9 @@ import { PackageJsonLookup } from '@rushstack/node-core-library'; import { EnvironmentVariableNames } from '../api/EnvironmentConfiguration'; -if (!process.env[EnvironmentVariableNames.RUSH_LIB_PATH]) { - const rootDir: string | undefined = PackageJsonLookup.instance.tryGetPackageFolderFor(__dirname); - if (rootDir) { - // Route to the 'main' field of package.json - const rushLibIndex: string = require.resolve(rootDir, { paths: [] }); - process.env[EnvironmentVariableNames.RUSH_LIB_PATH] = rushLibIndex; - } +const rootDir: string | undefined = PackageJsonLookup.instance.tryGetPackageFolderFor(__dirname); +if (rootDir) { + // Route to the 'main' field of package.json + const rushLibIndex: string = require.resolve(rootDir, { paths: [] }); + process.env[EnvironmentVariableNames.RUSH_LIB_PATH] = rushLibIndex; }