@@ -4,7 +4,7 @@ import { globals } from "./globals.js"
44import type { Builtins } from "./intrinsics.js"
55import { IntrinsicNames } from "./intrinsic-names.js"
66import { type AstNode , type Binding , PendingThrow } from "./model.js"
7- import { moduleName , resolveModule } from "./modules.js"
7+ import { isRuntimeModule , moduleName , resolveModule } from "./modules.js"
88import { define , entries , type HostNamespace , makingIntrinsics , nativeRule , Obj , type Value } from "./objects.js"
99import type { HostResult } from "../host.js"
1010import { Prelude } from "../prelude/prelude.js"
@@ -88,12 +88,7 @@ export class Interpreter<R> {
8888 const cached = this . modules . get ( name )
8989 if ( cached !== undefined ) return cached
9090 const module = resolveModule ( name , ( global ) => this . globalScope . get ( global ) ?. value , this . moduleGlobals )
91- if ( module === undefined )
92- throw new PendingThrow (
93- "Error" ,
94- `Cannot import "${ specifier } ": it isn't available here, where packages and files can't be loaded. Use the provided globals.` ,
95- site ,
96- )
91+ if ( module === undefined ) throw new PendingThrow ( "Error" , cannotImport ( specifier ) , site )
9792 this . modules . set ( name , module )
9893 return module
9994 }
@@ -135,3 +130,11 @@ export class Interpreter<R> {
135130 return this . sources . get ( id . source ) ?. node ( id )
136131 }
137132}
133+
134+ /** Why `specifier` can't be loaded, split so the error names the kind of import that failed. */
135+ function cannotImport ( specifier : string ) : string {
136+ if ( specifier . startsWith ( "." ) || specifier . startsWith ( "/" ) || specifier . startsWith ( "file:" ) )
137+ return `Cannot import "${ specifier } ": local files can't be imported.`
138+ if ( isRuntimeModule ( specifier ) ) return `Cannot import "${ specifier } ": this runtime doesn't provide it.`
139+ return `Cannot import "${ specifier } ": packages can't be installed here.`
140+ }
0 commit comments