Skip to content

Commit

Permalink
Print user friendly error if no entrypoint can be found (#1848)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeMoorJasper authored and devongovett committed Aug 23, 2018
1 parent 1721322 commit 0d2cf5f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
32 changes: 25 additions & 7 deletions packages/core/parcel/src/Bundler.js
Expand Up @@ -142,7 +142,9 @@ class Bundler extends EventEmitter {
contentHash:
typeof options.contentHash === 'boolean'
? options.contentHash
: isProduction
: isProduction,
throwErrors:
typeof options.throwErrors === 'boolean' ? options.throwErrors : true
};
}

Expand Down Expand Up @@ -223,6 +225,7 @@ class Bundler extends EventEmitter {

let isInitialBundle = !this.entryAssets;
let startTime = Date.now();
let initialised = !isInitialBundle;
this.pending = true;
this.error = null;

Expand All @@ -242,10 +245,24 @@ class Bundler extends EventEmitter {

this.entryAssets = new Set();
for (let entry of this.entryFiles) {
let asset = await this.resolveAsset(entry);
this.buildQueue.add(asset);
this.entryAssets.add(asset);
try {
let asset = await this.resolveAsset(entry);
this.buildQueue.add(asset);
this.entryAssets.add(asset);
} catch (err) {
throw new Error(
`Cannot resolve entry "${entry}" from "${
this.options.rootDir
}"`
);
}
}

if (this.entryAssets.size === 0) {
throw new Error('No entries found.');
}

initialised = true;
}

// Build the queued assets.
Expand Down Expand Up @@ -318,10 +335,11 @@ class Bundler extends EventEmitter {
this.hmr.emitError(err);
}

if (process.env.NODE_ENV === 'production') {
process.exitCode = 1;
} else if (process.env.NODE_ENV === 'test' && !this.hmr) {
if (this.options.throwErrors && !this.hmr) {
throw err;
} else if (process.env.NODE_ENV === 'production' || !initialised) {
await this.stop();
process.exit(1);
}
} finally {
this.pending = false;
Expand Down
1 change: 1 addition & 0 deletions packages/core/parcel/src/cli.js
Expand Up @@ -202,6 +202,7 @@ async function bundle(main, command) {
};
}

command.throwErrors = false;
command.scopeHoist = command.experimentalScopeHoisting || false;
const bundler = new Bundler(main, command);

Expand Down
3 changes: 2 additions & 1 deletion packages/core/parcel/test/utils.js
Expand Up @@ -37,7 +37,8 @@ function bundler(file, opts) {
cache: false,
killWorkers: false,
hmr: false,
logLevel: 0
logLevel: 0,
throwErrors: true
},
opts
)
Expand Down

0 comments on commit 0d2cf5f

Please sign in to comment.