{"record":{"id":"84488db1d3e4526c","repo":"cube-js/cube","slug":"required-import-for-filename-is-not-found","errorCode":null,"errorMessage":"Required import for ${fileName} is not found","messagePattern":"Required import for (.+?) is not found","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.ts","lineNumber":989,"sourceCode":"    return clone;\n  }\n\n  private standaloneCompileContextProxy() {\n    return new Proxy({}, {\n      get: () => {\n        throw new UserError('COMPILE_CONTEXT can\\'t be used unless contextToAppId is defined. Please see https://cube.dev/docs/config#options-reference-context-to-app-id.');\n      }\n    });\n  }\n\n  private resolveModuleFile(currentFile: FileContent, modulePath: string, toCompile: FileContent[], errorsReport: ErrorReporter) {\n    const localImport = modulePath.match(/^\\.\\/(.*)$/);\n\n    if (!currentFile.isModule && localImport) {\n      const fileName = localImport[1].match(/^.*\\.js$/) ? localImport[1] : `${localImport[1]}.js`;\n      const foundFile = toCompile.find((f) => f.fileName === fileName);\n      if (!foundFile) {\n        throw new UserError(`Required import for ${fileName} is not found`);\n      }\n      return foundFile;\n    }\n\n    const nodeModulesPath = path.resolve('node_modules');\n    let absPath = currentFile.isModule ?\n      path.resolve('node_modules', path.dirname(currentFile.fileName), modulePath) :\n      path.resolve('node_modules', modulePath);\n\n    if (!absPath.startsWith(nodeModulesPath)) {\n      if (this.allowNodeRequire) {\n        return null;\n      }\n      throw new UserError(`'${modulePath}' restricted`);\n    }\n    const packagePath = absPath.replace(nodeModulesPath, '').split('/').filter(s => !!s)[0];\n    if (!packagePath) {\n      if (this.allowNodeRequire) {","sourceCodeStart":971,"sourceCodeEnd":1007,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.ts#L971-L1007","documentation":"When a non-module data model file uses a relative import (`./file.js`), resolveModuleFile looks the file up in the list of files being compiled. If no file with that name is in the compile set, it throws this UserError. This catches imports pointing to files that don't exist or weren't included in compilation.","triggerScenarios":"A schema JS file does `const utils = require('./helpers.js')` (or the transpiled equivalent) but `helpers.js` is missing, has a different name/extension, or lives outside the schema directory that Cube watches, so it's not in toCompile.","commonSituations":"Importing shared JS helpers that live outside the configured schemaPath; wrong relative path after moving files; extension mismatch (file is .ts or .mjs while import says .js); files excluded from the repository that the compiler scans (e.g. .gitignore'd helpers, Docker image missing the file).","solutions":["Fix the relative path/extension so it exactly matches an existing file inside the schema directory.","Move shared JS modules into the schema folder (schemaPath) so the compiler includes them.","If using the repository/repositoryFactory API, ensure fileRepository includes the imported file.","For real npm dependencies, import by package name instead of a relative path (node_modules branch handles that)."],"exampleFix":"// before (schema/index.js)\nconst helpers = require('./utils/helpers.js'); // file lives at project root\n// after\nconst helpers = require('./helpers.js'); // copy helpers.js next to schema files, or use an npm package","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nconst target = `schema/${fileName}`;\nif (!fs.existsSync(target)) {\n  throw new Error(`Schema import target missing: ${target}`);\n}","typeGuard":null,"tryCatchPattern":"try { await compiler.compile(); } catch (e) { if (/Required import for .* is not found/.test(e.message)) { console.error('Fix relative path or move file into schemaPath:', e.message); } throw e; }","preventionTips":["Keep all imported JS helpers inside the schema directory","Match file extensions exactly (.js) in relative imports","Verify Docker/CI images include all schema helper files"],"tags":["schema-compiler","import-resolution","file-not-found"],"backgroundTag":"import-not-found","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}