Skip to content

Commit 12668b9

Browse files
authored
Friendly microbundle-specific resolve errors (#687)
1 parent 3f12b9f commit 12668b9

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

.changeset/angry-goats-knock.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"microbundle": patch
3+
---
4+
5+
Add friendly microbundle-specific errors when modules can't be resolved.

src/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,26 @@ function createConfig(options, entry, format, writeMeta) {
421421
}
422422
return externalTest(id);
423423
},
424+
425+
onwarn(warning, warn) {
426+
// https://github.com/rollup/rollup/blob/0fa9758cb7b1976537ae0875d085669e3a21e918/src/utils/error.ts#L324
427+
if (warning.code === 'UNRESOLVED_IMPORT') {
428+
stdout(
429+
`Failed to resolve the module ${warning.source} imported by ${warning.importer}` +
430+
`\nIs the module installed? Note:` +
431+
`\n ↳ to inline a module into your bundle, install it to "devDependencies".` +
432+
`\n ↳ to depend on a module via import/require, install it to "dependencies".`,
433+
);
434+
return;
435+
}
436+
437+
warn(warning);
438+
},
439+
424440
treeshake: {
425441
propertyReadSideEffects: false,
426442
},
443+
427444
plugins: []
428445
.concat(
429446
postcss({

0 commit comments

Comments
 (0)