Skip to content

Commit 320f20f

Browse files
fix: error on missing file (#83)
1 parent 3de90d1 commit 320f20f

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/resolver.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,19 @@ export function createDtsResolvePlugin({
7373
!dtsResolution ||
7474
(!RE_TS.test(dtsResolution) && !RE_VUE.test(dtsResolution))
7575
) {
76-
if (
76+
const unresolved =
7777
!rolldownResolution ||
7878
(!RE_TS.test(rolldownResolution.id) &&
7979
!RE_VUE.test(rolldownResolution.id))
80-
) {
80+
81+
if (unresolved) {
82+
// For relative/absolute type imports, surface an error instead of
83+
// silently externalizing so users know a local type file is missing.
84+
const isRelativeOrAbsolute =
85+
id.startsWith('.') || path.isAbsolute(id)
86+
if (isRelativeOrAbsolute) {
87+
return this.error(`Cannot resolve import '${id}' from '${importer}'`)
88+
}
8189
return external
8290
}
8391
dtsResolution = rolldownResolution.id
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './missing-file'

tests/index.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,16 @@ test('cjs exports', async () => {
164164
expect(snapshot).toMatchSnapshot()
165165
}
166166
})
167+
168+
test('should error when file import cannot be found', async () => {
169+
await expect(() =>
170+
rolldownBuild(
171+
path.resolve(dirname, 'fixtures/unresolved-import/index.d.ts'),
172+
[
173+
dts({
174+
emitDtsOnly: true,
175+
}),
176+
],
177+
),
178+
).rejects.toThrow("Cannot resolve import './missing-file'")
179+
})

0 commit comments

Comments
 (0)