Skip to content

Commit 85a58ae

Browse files
committed
feat: add friendly error for unloadable virtual modules
1 parent 7cfb72a commit 85a58ae

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

crates/rolldown_error/src/build_diagnostic/events/unloadable_dependency.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,11 @@ impl BuildEvent for UnloadableDependency {
6363
diagnostic.title = self.message(opts);
6464
}
6565
}
66+
67+
if self.resolved.starts_with("\\0") {
68+
diagnostic.add_help(String::from(
69+
"This module seems to be a virtual module, but no plugin handled it via the load hook.",
70+
));
71+
}
6672
}
6773
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { defineTest } from 'rolldown-tests';
2+
import { stripVTControlCharacters } from 'node:util';
3+
import { expect } from 'vitest';
4+
5+
export default defineTest({
6+
config: {
7+
plugins: [
8+
{
9+
name: 'test-virtual',
10+
resolveId(id) {
11+
if (id === 'virtual-module') {
12+
return '\0virtual-module';
13+
}
14+
},
15+
// intentionally no load hook
16+
},
17+
],
18+
},
19+
catchError(e: any) {
20+
for (const error of e.errors) {
21+
error.message = stripVTControlCharacters(error.message);
22+
}
23+
expect(e.errors).toEqual(
24+
expect.arrayContaining([
25+
expect.objectContaining({
26+
kind: 'UNLOADABLE_DEPENDENCY',
27+
message: expect.stringContaining(
28+
'This module seems to be a virtual module, but no plugin handled it via the load hook.',
29+
),
30+
}),
31+
]),
32+
);
33+
},
34+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import 'virtual-module';

0 commit comments

Comments
 (0)