Skip to content

Commit

Permalink
Friendly microbundle-specific resolve errors (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
developit committed Sep 28, 2020
1 parent 3f12b9f commit 12668b9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-goats-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"microbundle": patch
---

Add friendly microbundle-specific errors when modules can't be resolved.
17 changes: 17 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,26 @@ function createConfig(options, entry, format, writeMeta) {
}
return externalTest(id);
},

onwarn(warning, warn) {
// https://github.com/rollup/rollup/blob/0fa9758cb7b1976537ae0875d085669e3a21e918/src/utils/error.ts#L324
if (warning.code === 'UNRESOLVED_IMPORT') {
stdout(
`Failed to resolve the module ${warning.source} imported by ${warning.importer}` +
`\nIs the module installed? Note:` +
`\n ↳ to inline a module into your bundle, install it to "devDependencies".` +
`\n ↳ to depend on a module via import/require, install it to "dependencies".`,
);
return;
}

warn(warning);
},

treeshake: {
propertyReadSideEffects: false,
},

plugins: []
.concat(
postcss({
Expand Down

0 comments on commit 12668b9

Please sign in to comment.