Skip to content

Commit

Permalink
Display absolute path on failed dependency resolve. (#271)
Browse files Browse the repository at this point in the history
* Display absolute path on failed dependency resolve.

When a file path can not be resolved the error message is cleaned
up but the relative path to file is displayed.

In cases where a mistake have been made this path can be very confusing,
like `Cannot resolve dependency './../../../../../../main.js'` for when
a path starts with `/`.

This PR resolves attempted path into an absolute path in hope of
reducing confusion and minimize cognitive overhead of `..` chasing.

* Resolve absolute path relative to asset.

* Log both relative name and absolute search path.
  • Loading branch information
pomle authored and devongovett committed Dec 20, 2017
1 parent 9376ddd commit dffeb7d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ class Bundler extends EventEmitter {
return await this.resolveAsset(dep.name, asset.name);
} catch (err) {
if (err.message.indexOf(`Cannot find module '${dep.name}'`) === 0) {
err.message = `Cannot resolve dependency '${dep.name}'`;
const absPath = Path.resolve(Path.dirname(asset.name), dep.name);
err.message = `Cannot resolve dependency '${dep.name}' at '${absPath}'`;

// Generate a code frame where the dependency was used
if (dep.loc) {
Expand Down

0 comments on commit dffeb7d

Please sign in to comment.