Skip to content

Commit

Permalink
fix: catch error when resolving peer dep (#13334)
Browse files Browse the repository at this point in the history
fixes #13331
  • Loading branch information
eltigerchino authored Jan 17, 2025
1 parent 777c8ef commit 388d441
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/kit/src/utils/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ export async function resolve_peer_dependency(dependency) {
try {
// @ts-expect-error the types are wrong
const resolved = imr.resolve(dependency, pathToFileURL(process.cwd() + '/dummy.js'));
return await import(resolved).catch(() => import(dependency));
return await import(resolved);
} catch {
throw new Error(
`Could not resolve peer dependency "${dependency}" relative to your project — please install it and try again.`
);
try {
// both imr.resolve and await import above can throw, which is why we can't just do import(resolved).catch(...) above
return await import(dependency);
} catch {
throw new Error(
`Could not resolve peer dependency "${dependency}" relative to your project — please install it and try again.`
);
}
}
}

0 comments on commit 388d441

Please sign in to comment.