From 4048a31b7abd586ccc905925c7a8c6403d81b458 Mon Sep 17 00:00:00 2001 From: DeMoorJasper Date: Fri, 3 Aug 2018 11:02:20 -0700 Subject: [PATCH 1/5] print user friendly error if no entrypoint can be found --- src/Bundler.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Bundler.js b/src/Bundler.js index d02c93eb857..6c67e446a0d 100644 --- a/src/Bundler.js +++ b/src/Bundler.js @@ -223,6 +223,7 @@ class Bundler extends EventEmitter { let isInitialBundle = !this.entryAssets; let startTime = Date.now(); + let initialised = !isInitialBundle; this.pending = true; this.error = null; @@ -242,10 +243,20 @@ 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(`Failed to load entrypoint: ${entry}!`); + } + } + + if (this.entryAssets.size === 0) { + throw new Error('No entrypoint(s) found.'); } + + initialised = true; } // Build the queued assets. @@ -318,8 +329,12 @@ class Bundler extends EventEmitter { this.hmr.emitError(err); } - if (process.env.NODE_ENV === 'production') { - process.exitCode = 1; + if ( + process.env.NODE_ENV === 'production' || + (isInitialBundle && !initialised) + ) { + await this.stop(); + process.exit(1); } else if (process.env.NODE_ENV === 'test' && !this.hmr) { throw err; } From 2b191f4b2bb1c12a0cab4a6c7998b18093605250 Mon Sep 17 00:00:00 2001 From: DeMoorJasper Date: Fri, 3 Aug 2018 11:05:19 -0700 Subject: [PATCH 2/5] remove useless isInitial check --- src/Bundler.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Bundler.js b/src/Bundler.js index 6c67e446a0d..ccf7616ca80 100644 --- a/src/Bundler.js +++ b/src/Bundler.js @@ -329,10 +329,7 @@ class Bundler extends EventEmitter { this.hmr.emitError(err); } - if ( - process.env.NODE_ENV === 'production' || - (isInitialBundle && !initialised) - ) { + if (process.env.NODE_ENV === 'production' || !initialised) { await this.stop(); process.exit(1); } else if (process.env.NODE_ENV === 'test' && !this.hmr) { From ea56814b44b91c5d33cdca3aa01b6cc4a323870b Mon Sep 17 00:00:00 2001 From: DeMoorJasper Date: Fri, 10 Aug 2018 11:09:05 -0700 Subject: [PATCH 3/5] fix bundler error throwing --- src/Bundler.js | 12 ++++++++---- test/utils.js | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Bundler.js b/src/Bundler.js index ccf7616ca80..1e59d4b278b 100644 --- a/src/Bundler.js +++ b/src/Bundler.js @@ -142,7 +142,11 @@ class Bundler extends EventEmitter { contentHash: typeof options.contentHash === 'boolean' ? options.contentHash - : isProduction + : isProduction, + throwErrors: + typeof options.throwErrors === 'boolean' + ? options.throwErrors + : process.env.NODE_ENV === 'test' }; } @@ -329,11 +333,11 @@ class Bundler extends EventEmitter { this.hmr.emitError(err); } - if (process.env.NODE_ENV === 'production' || !initialised) { + if (this.options.throwErrors && !this.hmr) { + throw err; + } else if (process.env.NODE_ENV === 'production' || !initialised) { await this.stop(); process.exit(1); - } else if (process.env.NODE_ENV === 'test' && !this.hmr) { - throw err; } } finally { this.pending = false; diff --git a/test/utils.js b/test/utils.js index fd65563cc47..8e6d70a7614 100644 --- a/test/utils.js +++ b/test/utils.js @@ -37,7 +37,8 @@ function bundler(file, opts) { cache: false, killWorkers: false, hmr: false, - logLevel: 0 + logLevel: 0, + throwErrors: true }, opts ) From 8c3ace7ebbbf210392e0edd2f9832ee45c1684ad Mon Sep 17 00:00:00 2001 From: DeMoorJasper Date: Thu, 16 Aug 2018 09:06:01 -0700 Subject: [PATCH 4/5] improve error message and always throw in non-cli environment --- src/Bundler.js | 10 ++++++---- src/cli.js | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Bundler.js b/src/Bundler.js index 1e59d4b278b..e61fb9509e9 100644 --- a/src/Bundler.js +++ b/src/Bundler.js @@ -144,9 +144,7 @@ class Bundler extends EventEmitter { ? options.contentHash : isProduction, throwErrors: - typeof options.throwErrors === 'boolean' - ? options.throwErrors - : process.env.NODE_ENV === 'test' + typeof options.throwErrors === 'boolean' ? options.throwErrors : true }; } @@ -252,7 +250,11 @@ class Bundler extends EventEmitter { this.buildQueue.add(asset); this.entryAssets.add(asset); } catch (err) { - throw new Error(`Failed to load entrypoint: ${entry}!`); + throw new Error( + `Failed to load entrypoint: "${entry}" in "${ + this.options.rootDir + }"` + ); } } diff --git a/src/cli.js b/src/cli.js index 01207a816c2..1723c1cbd47 100755 --- a/src/cli.js +++ b/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); From 7bb53cb80a3098a725471b5410da338c2b4432c0 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Thu, 23 Aug 2018 11:49:46 -0700 Subject: [PATCH 5/5] Update Bundler.js --- src/Bundler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bundler.js b/src/Bundler.js index e61fb9509e9..0fd1609c0cb 100644 --- a/src/Bundler.js +++ b/src/Bundler.js @@ -251,7 +251,7 @@ class Bundler extends EventEmitter { this.entryAssets.add(asset); } catch (err) { throw new Error( - `Failed to load entrypoint: "${entry}" in "${ + `Cannot resolve entry "${entry}" from "${ this.options.rootDir }"` ); @@ -259,7 +259,7 @@ class Bundler extends EventEmitter { } if (this.entryAssets.size === 0) { - throw new Error('No entrypoint(s) found.'); + throw new Error('No entries found.'); } initialised = true;