{"record":{"id":"4598b3ab9c1c1179","repo":"dotnet/aspnetcore","slug":"for-a-resourcetype-resource-custom-loaders-mus","errorCode":null,"errorMessage":"For a ${resourceType} resource, custom loaders must supply a URI string.","messagePattern":"For a (.+?) resource, custom loaders must supply a URI string\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts","lineNumber":137,"sourceCode":"};\n\nasync function importDotnetJs(startOptions: Partial<WebAssemblyStartOptions>): Promise<ModuleAPI> {\n  const browserSupportsNativeWebAssembly = typeof WebAssembly !== 'undefined' && WebAssembly.validate;\n  if (!browserSupportsNativeWebAssembly) {\n    throw new Error('This browser does not support WebAssembly.');\n  }\n\n\n  // Allow overriding the URI from which the dotnet.*.js file is loaded\n  if (startOptions.loadBootResource) {\n    const resourceType: WebAssemblyBootResourceType = 'dotnetjs';\n    const customSrc = startOptions.loadBootResource(resourceType, 'dotnet.js', '_framework/dotnet.js', '', 'js-module-dotnet');\n    if (typeof (customSrc) === 'string') {\n      const absoluteSrc = (new URL(customSrc, document.baseURI)).toString();\n      return await import(/* webpackIgnore: true */ absoluteSrc);\n    } else if (customSrc) {\n      // Since we must load this via a import, it's only valid to supply a URI (and not a Request, say)\n      throw new Error(`For a ${resourceType} resource, custom loaders must supply a URI string.`);\n    }\n  }\n\n  // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n  // @ts-ignore: This dynamic import is handled at runtime and does not need a type declaration.\n  return await import(/* webpackIgnore: true */ './dotnet.js');\n}\n\nfunction prepareRuntimeConfig(options: Partial<WebAssemblyStartOptions>, onConfigLoadedCallback?: (loadedConfig: MonoConfig) => void): DotnetModuleConfig {\n  const config: MonoConfig = {\n    maxParallelDownloads: 1000000, // disable throttling parallel downloads\n    enableDownloadRetry: false, // disable retry downloads\n  };\n\n  if (options.environment) {\n    config.applicationEnvironment = options.environment;\n  }\n","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts#L119-L155","documentation":"Thrown by importDotnetJs when a custom loadBootResource callback returns a truthy, non-string value for the 'dotnetjs' resource type. The dotnet.js module must be loaded via dynamic import(), which only accepts a URI string — a Response/Request/object is not valid here, unlike other resource types the custom loader can return.","triggerScenarios":"Implementing options.loadBootResource and returning a Response, Request, or object for the resourceType === 'dotnetjs' case instead of a URL string.","commonSituations":"Writing a generic loadBootResource that uniformly returns fetch() Responses for all resource types; CDN/offline cache strategies that try to serve dotnet.js from a Cache Response.","solutions":["For the 'dotnetjs' resource type, return a URI string (the URL to your cached/CDN dotnet.js), or return null/undefined to use the default.","Branch loadBootResource on resourceType and only override dotnetjs with a string URL.","If you must cache, precache the file and return its object URL string."],"exampleFix":"// before\nloadBootResource: (type, name, uri) => cache.match(uri) // Response — invalid for dotnetjs\n\n// after\nloadBootResource: (type, name, uri) =>\n  type === 'dotnetjs' ? `${cdnBase}/dotnet.js` : cache.match(uri)","handlingStrategy":"validation","validationCode":"// Validate loadBootResource return for dotnetjs.\nfunction loadBootResource(type, name, uri) {\n  if (type === 'dotnetjs') {\n    const url = `${cdnBase}/${name}`;\n    return typeof url === 'string' ? url : undefined; // string or default\n  }\n  return fetch(uri);\n}","typeGuard":"function isStringUrl(v: unknown): v is string {\n  return typeof v === 'string' && v.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Branch loadBootResource on resourceType; return only a string URL for 'dotnetjs'.","Return null/undefined to use default loading when unsure.","Do not return Response/Request objects for the dotnetjs resource."],"tags":["blazor-wasm","boot","loadbootresource","configuration"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}