Skip to content

Commit

Permalink
improve rollup error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed May 30, 2020
1 parent cbc7e61 commit 8488618
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
22 changes: 10 additions & 12 deletions src/commands/install.ts
Expand Up @@ -400,22 +400,20 @@ export async function install(
const packageBundle = await rollup(inputOptions);
logUpdate(formatInstallResults());
await packageBundle.write(outputOptions);
} catch (err) {
const {loc} = err as RollupError;
if (!loc || !loc.file) {
} catch (_err) {
const err: RollupError = _err;
const errFilePath = err.loc?.file || err.id;
if (!errFilePath) {
throw err;
}
// NOTE: Rollup will fail instantly on error. Because of that, we can
// NOTE: Rollup will fail instantly on most errors. Therefore, we can
// only report one error at a time. `err.watchFiles` also exists, but
// for now `err.loc.file` has all the information that we need.
const failedExtension = path.extname(loc.file);
const suggestion = MISSING_PLUGIN_SUGGESTIONS[failedExtension];
if (!suggestion) {
throw err;
}
// for now `err.loc.file` and `err.id` have all the info that we need.
const failedExtension = path.extname(errFilePath);
const suggestion = MISSING_PLUGIN_SUGGESTIONS[failedExtension] || err.message;
// Display posix-style on all environments, mainly to help with CI :)
const fileName = loc.file.replace(cwd + path.sep, '').replace(/\\/g, '/');
logError(`${chalk.bold('snowpack')} could not import ${fileName}. ${suggestion}`);
const fileName = errFilePath.replace(cwd + path.sep, '').replace(/\\/g, '/');
logError(`${chalk.bold('snowpack')} failed to load ${chalk.bold(fileName)}\n ${suggestion}`);
return;
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/integration/error-file-ext/expected-output.txt
@@ -1,3 +1,4 @@
- snowpack installing...
⠼ snowpack installing... dep-a
✖ snowpack could not import node_modules/dep-b/index.vue. Try installing rollup-plugin-vue and adding it to Snowpack (https://www.snowpack.dev/#custom-rollup-plugins)
✖ snowpack failed to load node_modules/dep-b/index.vue
Try installing rollup-plugin-vue and adding it to Snowpack (https://www.snowpack.dev/#custom-rollup-plugins)

0 comments on commit 8488618

Please sign in to comment.