Skip to content

chore: better error message when import within/from package fails #1386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/repl/src/lib/workers/bundler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ async function get_bundle(
const { name, version } = current.meta;
const path = new URL(importee, importer).href.replace(`${NPM}/${name}@${version}/`, '');

return normalize_path(current, path);
return normalize_path(current, path, importee, importer);
}

return new URL(importee, importer).href;
Expand All @@ -225,7 +225,7 @@ async function get_bundle(
if (importee[0] === '#') {
if (current) {
const subpath = resolve_subpath(current, importee);
return normalize_path(current, subpath.slice(2));
return normalize_path(current, subpath.slice(2), importee, importer);
}
return await resolve_local(importee);
}
Expand Down Expand Up @@ -266,7 +266,7 @@ async function get_bundle(
const pkg = await fetch_package(pkg_name, pkg_name === 'svelte' ? svelte_version : v);
const subpath = resolve_subpath(pkg, '.' + (match[3] ?? ''));

return normalize_path(pkg, subpath.slice(2));
return normalize_path(pkg, subpath.slice(2), importee, importer);
},
async load(resolved) {
if (uid !== current_id) throw ABORT;
Expand Down
6 changes: 4 additions & 2 deletions packages/repl/src/lib/workers/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export function resolve_subpath(pkg: Package, subpath: string): string {
return subpath;
}

export function normalize_path(pkg: Package, path: string) {
export function normalize_path(pkg: Package, path: string, importee: string, importer: string) {
for (const suffix of ['', '.js', '.mjs', '.cjs', '/index.js', '/index.mjs', '/index.cjs']) {
let with_suffix = path + suffix;

Expand All @@ -210,7 +210,9 @@ export function normalize_path(pkg: Package, path: string) {
}
}

throw new Error(`Could not find ${path} in ${pkg.meta.name}@${pkg.meta.version}`);
throw new Error(
`Could not find ${path} in ${pkg.meta.name}@${pkg.meta.version} (error occurred while trying to resolve ${importee} within ${importer})`
);
}

const LOCAL_PKG_URL = `${location.origin}/svelte/package.json`;
Expand Down