diff --git a/packages/core/parcel-bundler/src/Bundler.js b/packages/core/parcel-bundler/src/Bundler.js index d02c93eb857..0fd1609c0cb 100644 --- a/packages/core/parcel-bundler/src/Bundler.js +++ b/packages/core/parcel-bundler/src/Bundler.js @@ -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 }; } @@ -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; @@ -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. @@ -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; diff --git a/packages/core/parcel-bundler/src/cli.js b/packages/core/parcel-bundler/src/cli.js index 01207a816c2..1723c1cbd47 100755 --- a/packages/core/parcel-bundler/src/cli.js +++ b/packages/core/parcel-bundler/src/cli.js @@ -202,6 +202,7 @@ async function bundle(main, command) { }; } + command.throwErrors = false; command.scopeHoist = command.experimentalScopeHoisting || false; const bundler = new Bundler(main, command); diff --git a/packages/core/parcel-bundler/test/utils.js b/packages/core/parcel-bundler/test/utils.js index fd65563cc47..8e6d70a7614 100644 --- a/packages/core/parcel-bundler/test/utils.js +++ b/packages/core/parcel-bundler/test/utils.js @@ -37,7 +37,8 @@ function bundler(file, opts) { cache: false, killWorkers: false, hmr: false, - logLevel: 0 + logLevel: 0, + throwErrors: true }, opts )