diff --git a/.changeset/angry-goats-knock.md b/.changeset/angry-goats-knock.md new file mode 100644 index 00000000..71d6dbb9 --- /dev/null +++ b/.changeset/angry-goats-knock.md @@ -0,0 +1,5 @@ +--- +"microbundle": patch +--- + +Add friendly microbundle-specific errors when modules can't be resolved. diff --git a/src/index.js b/src/index.js index 2e41cea3..9b331d1e 100644 --- a/src/index.js +++ b/src/index.js @@ -412,9 +412,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({