{"record":{"id":"521ccf8ff742e484","repo":"BabylonJS/Babylon.js","slug":"loadfileinjection-is-not-defined","errorCode":null,"errorMessage":"loadFileInjection is not defined","messagePattern":"loadFileInjection is not defined","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Materials/effect.functions.ts","lineNumber":273,"sourceCode":"        return;\r\n    }\r\n\r\n    if (optionalKey && shaderStore[shader + optionalKey + \"Shader\"]) {\r\n        callback(shaderStore[shader + optionalKey + \"Shader\"]);\r\n        return;\r\n    }\r\n\r\n    let shaderUrl;\r\n\r\n    if (shader[0] === \".\" || shader[0] === \"/\" || shader.indexOf(\"http\") > -1) {\r\n        shaderUrl = shader;\r\n    } else {\r\n        shaderUrl = ShaderStore.GetShadersRepository(shaderLanguage) + shader;\r\n    }\r\n    _loadFileInjection = _loadFileInjection || _LoadFile;\r\n    if (!_loadFileInjection) {\r\n        // we got to this point and loadFile was not injected - throw an error\r\n        throw new Error(\"loadFileInjection is not defined\");\r\n    }\r\n    // Vertex shader\r\n    _loadFileInjection(shaderUrl + \".\" + key.toLowerCase() + \".fx\", callback);\r\n}\r\n\r\nfunction UseFinalCode(migratedVertexCode: string, migratedFragmentCode: string, baseName: any, shaderLanguage?: ShaderLanguage) {\r\n    if (baseName) {\r\n        const vertex = baseName.vertexElement || baseName.vertex || baseName.spectorName || baseName;\r\n        const fragment = baseName.fragmentElement || baseName.fragment || baseName.spectorName || baseName;\r\n\r\n        return {\r\n            vertexSourceCode: (shaderLanguage === ShaderLanguage.WGSL ? \"//\" : \"\") + \"#define SHADER_NAME vertex:\" + vertex + \"\\n\" + migratedVertexCode,\r\n            fragmentSourceCode: (shaderLanguage === ShaderLanguage.WGSL ? \"//\" : \"\") + \"#define SHADER_NAME fragment:\" + fragment + \"\\n\" + migratedFragmentCode,\r\n        };\r\n    } else {\r\n        return {\r\n            vertexSourceCode: migratedVertexCode,\r\n            fragmentSourceCode: migratedFragmentCode,\r","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Materials/effect.functions.ts#L255-L291","documentation":"Loading shader files (.fx) requires a file-loading function to be injected into the core (normally done by importing the side-effect module of the engine/file loader, e.g. @babylonjs/core/Materials/Textures/loadFile or the engine's injection). If _loadFileInjection is still unset, LoadShader throws instead of silently failing.","triggerScenarios":"Calling LoadShader (via _ProcessShaderCode / ShaderMaterial / Effect creation) in a tree-shaken ES6 setup where no LoadFile injection module was imported, so no file loader is registered.","commonSituations":"Using @babylonjs/core ES6 packages with tree shaking and forgetting to import side-effect modules, switching from the UMD bundle (auto-injected) to modular imports, custom DI setups that cleared injections.","solutions":["Import the file-loading side-effect: import \"@babylonjs/core/Materials/Textures/loadFile\"; (or the full engine entry) before creating shaders.","Alternatively inject manually: import { LoadFile } from ...; and set the injection (e.g. via the module that sets _loadFileInjection).","If you don't need file loading, use inline shader code (shaderStore / Effect.ShadersStore) instead of .fx URLs.","Audit your imports against the ES6 migration guide to ensure all needed side-effect modules are present."],"exampleFix":"// before\nimport { ShaderMaterial } from \"@babylonjs/core/Materials/shaderMaterial\";\n// after\nimport { ShaderMaterial } from \"@babylonjs/core/Materials/shaderMaterial\";\nimport \"@babylonjs/core/Materials/Textures/loadFile\"; // registers the loadFile injection","handlingStrategy":"try-catch","validationCode":"// Ensure the file-loader side effect is imported before shader creation\nimport \"@babylonjs/core/Materials/Textures/loadFile\";\n// or verify at runtime:\nif (!ShaderStore.ShadersRepository) {\n  console.warn(\"Shader repository/file loader not registered\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  const shader = new ShaderMaterial(\"m\", scene, \"./myShader\", {});\n} catch (e) {\n  if (String(e.message).includes(\"loadFileInjection is not defined\")) {\n    console.error(\"Import the loadFile side-effect module in your ES6 entry point.\");\n  }\n}","preventionTips":["In tree-shaken ES6 projects, import all needed side-effect modules listed in the ES6 migration guide.","Keep a single app entry that imports the Babylon.js engine + loaders once.","Prefer inline ShaderStore shaders when no file loading is desired."],"tags":["es6-tree-shaking","shader-loading","dependency-injection","missing-import"],"backgroundTag":"missing-loadfile-injection","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}