Skip to content

Commit 3ab3344

Browse files
authored
fix: searchPackageVersion package.json resolution (#294)
1 parent 7114b38 commit 3ab3344

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/utils/normalizeModuleFederationOptions.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,17 @@ function searchPackageVersion(sharedName: string): string | undefined {
133133
path.parse(potentialPackageJsonDir).base !== 'node_modules' &&
134134
potentialPackageJsonDir !== rootDir
135135
) {
136-
const potentialPackageJson = path.join(potentialPackageJsonDir, 'package.json');
137-
if (fs.existsSync(potentialPackageJson)) {
138-
return require(potentialPackageJson).version;
136+
const potentialPackageJsonPath = path.join(potentialPackageJsonDir, 'package.json');
137+
if (fs.existsSync(potentialPackageJsonPath)) {
138+
const potentialPackageJson = require(potentialPackageJsonPath);
139+
if (
140+
typeof potentialPackageJson == 'object' &&
141+
potentialPackageJson !== null &&
142+
typeof potentialPackageJson.version === 'string' &&
143+
potentialPackageJson.name === sharedName
144+
) {
145+
return potentialPackageJson.version;
146+
}
139147
}
140148
potentialPackageJsonDir = path.dirname(potentialPackageJsonDir);
141149
}

0 commit comments

Comments
 (0)