New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Print user friendly error if no entrypoint can be found #1848
Changes from 3 commits
4048a31
2b191f4
ea56814
8c3ace7
7bb53cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' | ||
}; | ||
} | ||
|
||
|
@@ -223,6 +227,7 @@ class Bundler extends EventEmitter { | |
|
||
let isInitialBundle = !this.entryAssets; | ||
let startTime = Date.now(); | ||
let initialised = !isInitialBundle; | ||
this.pending = true; | ||
this.error = null; | ||
|
||
|
@@ -242,10 +247,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}!`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of a more precise error message, something like: Given that we infer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure thing, I'll update it |
||
} | ||
} | ||
|
||
if (this.entryAssets.size === 0) { | ||
throw new Error('No entrypoint(s) found.'); | ||
} | ||
|
||
initialised = true; | ||
} | ||
|
||
// Build the queued assets. | ||
|
@@ -318,10 +333,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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently |
||
} | ||
} finally { | ||
this.pending = false; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should default this to
false
in CLI andtrue
when using theBundler
API.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, I'll update it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be considered a breaking change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just something I thought about, parcel already throws errors in the api using the event handler.
So this might cause issues as the promise of bundle only returns on initial build. What do you think?