Skip to content

Commit e4ced3a

Browse files
authored
chore: better error message when import within/from package fails (#1386)
hopefully makes debugging cases easier
1 parent 1d6dbf6 commit e4ced3a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

packages/repl/src/lib/workers/bundler/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ async function get_bundle(
215215
const { name, version } = current.meta;
216216
const path = new URL(importee, importer).href.replace(`${NPM}/${name}@${version}/`, '');
217217

218-
return normalize_path(current, path);
218+
return normalize_path(current, path, importee, importer);
219219
}
220220

221221
return new URL(importee, importer).href;
@@ -225,7 +225,7 @@ async function get_bundle(
225225
if (importee[0] === '#') {
226226
if (current) {
227227
const subpath = resolve_subpath(current, importee);
228-
return normalize_path(current, subpath.slice(2));
228+
return normalize_path(current, subpath.slice(2), importee, importer);
229229
}
230230
return await resolve_local(importee);
231231
}
@@ -266,7 +266,7 @@ async function get_bundle(
266266
const pkg = await fetch_package(pkg_name, pkg_name === 'svelte' ? svelte_version : v);
267267
const subpath = resolve_subpath(pkg, '.' + (match[3] ?? ''));
268268

269-
return normalize_path(pkg, subpath.slice(2));
269+
return normalize_path(pkg, subpath.slice(2), importee, importer);
270270
},
271271
async load(resolved) {
272272
if (uid !== current_id) throw ABORT;

packages/repl/src/lib/workers/npm.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export function resolve_subpath(pkg: Package, subpath: string): string {
195195
return subpath;
196196
}
197197

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

@@ -210,7 +210,9 @@ export function normalize_path(pkg: Package, path: string) {
210210
}
211211
}
212212

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

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

0 commit comments

Comments
 (0)