File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed
fixtures/unresolved-import Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 1+ export * from './missing-file'
Original file line number Diff line number Diff 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+ } )
You can’t perform that action at this time.
0 commit comments