Skip to content

Commit

Permalink
Include versions in externals error message (#68871)
Browse files Browse the repository at this point in the history
Now the expected and actual version numbers are included in the error
message:
```
Package @libsql/client (serverExternalPackages or default list) can't be external
The request @libsql/client matches serverExternalPackages (or the default list), but it can't be external:
The package resolves to a different version when requested from the project directory (0.9.0) compared to the package requested from the importing module (0.6.2).
Make sure to install the same version of the package in both locations.
```
  • Loading branch information
mischnic authored and ForsakenHarmony committed Aug 15, 2024
1 parent d187420 commit 26f4c59
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions crates/next-core/src/next_server/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,31 +308,38 @@ impl AfterResolvePlugin for ExternalCjsModulesResolvePlugin {
);
};
let (Some(name), Some(version)) = (
package_json_file.get("name"),
package_json_file.get("version"),
package_json_file.get("name").and_then(|v| v.as_str()),
package_json_file.get("version").and_then(|v| v.as_str()),
) else {
return unable_to_externalize(
request_str.into(),
"The package.json of the package has not name or version.",
"The package.json of the package has no name or version.",
);
};
let (Some(name2), Some(version2)) = (
package_json_from_original_location.get("name"),
package_json_from_original_location.get("version"),
package_json_from_original_location
.get("name")
.and_then(|v| v.as_str()),
package_json_from_original_location
.get("version")
.and_then(|v| v.as_str()),
) else {
return unable_to_externalize(
request_str.into(),
"The package.json of the package resolved from project directory has not name \
"The package.json of the package resolved from project directory has no name \
or version.",
);
};
if (name, version) != (name2, version2) {
// this can't resolve with node.js from the original location, so bundle it
return unable_to_externalize(
request_str.into(),
"The package resolves to a different version when requested from the project \
directory compared to the package requested from the importing module.\nMake \
sure to install the same version of the package in both locations.",
&format!(
"The package resolves to a different version when requested from the \
project directory ({version}) compared to the package requested from the \
importing module ({version2}).\nMake sure to install the same version of \
the package in both locations."
),
);
}
}
Expand Down

0 comments on commit 26f4c59

Please sign in to comment.