{"record":{"id":"bc5cc4e19106a2f7","repo":"phaserjs/phaser","slug":"url-error-in-file","errorCode":null,"errorMessage":"URL Error in File: ","messagePattern":"URL Error in File: ","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/loader/File.js","lineNumber":324,"sourceCode":"     * @method Phaser.Loader.File#load\n     * @since 3.0.0\n     */\n    load: function ()\n    {\n        if (this.state === CONST.FILE_POPULATED)\n        {\n            //  Can happen for example in a JSONFile if they've provided a JSON object instead of a URL\n            this.loader.nextFile(this, true);\n        }\n        else\n        {\n            this.state = CONST.FILE_LOADING;\n\n            this.src = GetURL(this, this.loader.baseURL);\n\n            if (!this.src)\n            {\n                throw new Error('URL Error in File: ' + this.key + ' from: ' + this.url);\n            }\n\n            if (this.src.indexOf('data:') === 0)\n            {\n                this.base64 = true;\n            }\n\n            this.xhrLoader = XHRLoader(this, this.loader.xhr);\n        }\n    },\n\n    /**\n     * Called when the file finishes loading, is sent a DOM ProgressEvent.\n     *\n     * @method Phaser.Loader.File#onLoad\n     * @since 3.0.0\n     *\n     * @param {XMLHttpRequest} xhr - The XMLHttpRequest that caused this onload event.","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/phaserjs/phaser/blob/41be1e462bc600064e498cba370bfa8c5c055a22/src/loader/File.js#L306-L342","documentation":"File.js:324 throws when `GetURL(this, this.loader.baseURL)` returns falsy. Per GetURL.js:25, that happens only when `file.url` itself is falsy — i.e. the file's url resolved to an empty string/null/undefined after the constructor's url logic (File.js:78-89) ran. An absolute url is returned as-is, so this guard specifically catches a missing relative url.","triggerScenarios":"Constructing a File with no `url` and no/empty `extension`, so the constructor builds `url = path + key + '.'` only if extension is truthy — if extension defaulted to '' AND url was explicitly set to a falsy value, the resolved url is falsy and GetURL returns false. Also when `url: null` is passed explicitly.","commonSituations":"Custom File subclasses that compute url conditionally and leave it unset; configs where `url` is conditionally provided by a template that rendered empty; passing `url: ''` thinking the loader will infer a default.","solutions":["Provide a non-empty `url` (relative or absolute) in the file config, or an `extension` so the url can be auto-built from `path + key + '.' + extension`.","If using a prefix/path, ensure `loader.path` + key + extension forms a valid string.","Avoid setting `url: null`/`url: ''`; omit the field only when you also supply `extension`."],"exampleFix":"// before\nnew Phaser.Loader.File({ type: 'image', key: 'hero', url: '' })\n// after\nnew Phaser.Loader.File({ type: 'image', key: 'hero', extension: 'png' }) // url auto-built","handlingStrategy":"validation","validationCode":"const url = fileConfig.url || (fileConfig.key + '.' + (fileConfig.extension || ''))\nif (!url) {\n  throw new Error('File config needs a url or an extension to build one')\n}\nconst file = new Phaser.Loader.File(fileConfig)","typeGuard":"const hasResolvableUrl = (c) => typeof c?.url === 'string' && c.url.length > 0 || (typeof c?.extension === 'string' && c.extension.length > 0)","tryCatchPattern":null,"preventionTips":["Always supply a non-empty url, or both key and extension so the url can be auto-built.","Avoid passing url: null/'' explicitly.","Set loader.path/baseURL consistently so relative urls resolve."],"tags":["loader","file","url","validation"],"backgroundTag":null,"analyzedSha":"41be1e462bc600064e498cba370bfa8c5c055a22","analyzedAt":"2026-08-13T04:23:39.729Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}