File tree 2 files changed +26
-5
lines changed
2 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -719,7 +719,25 @@ let loadTS: (() => typeof TS) | undefined
719
719
* @private
720
720
*/
721
721
export function registerTS ( _loadTS : ( ) => typeof TS ) {
722
- loadTS = _loadTS
722
+ loadTS = ( ) => {
723
+ try {
724
+ return _loadTS ( )
725
+ } catch ( err : any ) {
726
+ if (
727
+ typeof err . message === 'string' &&
728
+ err . message . includes ( 'Cannot find module' )
729
+ ) {
730
+ throw new Error (
731
+ 'Failed to load TypeScript, which is required for resolving imported types. ' +
732
+ 'Please make sure "typescript" is installed as a project dependency.'
733
+ )
734
+ } else {
735
+ throw new Error (
736
+ 'Failed to load TypeScript for resolving imported types.'
737
+ )
738
+ }
739
+ }
740
+ }
723
741
}
724
742
725
743
type FS = NonNullable < SFCScriptCompileOptions [ 'fs' ] >
@@ -768,7 +786,12 @@ function importSourceToScope(
768
786
scope : TypeScope ,
769
787
source : string
770
788
) : TypeScope {
771
- const fs = resolveFS ( ctx )
789
+ let fs : FS | undefined
790
+ try {
791
+ fs = resolveFS ( ctx )
792
+ } catch ( err : any ) {
793
+ return ctx . error ( err . message , node , scope )
794
+ }
772
795
if ( ! fs ) {
773
796
return ctx . error (
774
797
`No fs option provided to \`compileScript\` in non-Node environment. ` +
Original file line number Diff line number Diff line change 1
1
if ( typeof require !== 'undefined' ) {
2
- try {
3
- require ( '@vue/compiler-sfc' ) . registerTS ( ( ) => require ( 'typescript' ) )
4
- } catch ( e ) { }
2
+ require ( '@vue/compiler-sfc' ) . registerTS ( ( ) => require ( 'typescript' ) )
5
3
}
You can’t perform that action at this time.
0 commit comments