{"record":{"id":"a18e66893902db51","repo":"cube-js/cube","slug":"compile-context-can-t-be-used-unless-contexttoappi","errorCode":null,"errorMessage":"COMPILE_CONTEXT can't be used unless contextToAppId is defined. Please see https://cube.dev/docs/config#options-reference-context-to-app-id.","messagePattern":"COMPILE_CONTEXT can't be used unless contextToAppId is defined\\. Please see https://cube\\.dev/docs/config#options-reference-context-to-app-id\\.","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.ts","lineNumber":977,"sourceCode":"      });\n    } catch (e) {\n      errorsReport.error(e);\n    }\n  }\n\n  // Alias \"securityContext\" with \"security_context\" (snake case version)\n  // to support snake case based data models\n  private cloneCompileContextWithGetterAlias(compileContext) {\n    const ctx = compileContext || {};\n    const clone = R.clone(ctx);\n    clone.security_context = ctx.securityContext;\n    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 ?","sourceCodeStart":959,"sourceCodeEnd":995,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.ts#L959-L995","documentation":"standaloneCompileContextProxy returns a Proxy whose every property access throws this UserError. It is installed when COMPILE_CONTEXT is referenced but the app has not configured contextToAppId, meaning compile-time context switching (per-app compiling) is not possible. The error tells you to enable multitenant compilation first.","triggerScenarios":"A data model references `${COMPILE_CONTEXT.something}` (e.g. to build per-tenant schemas) while the server config lacks `contextToAppId`, or COMPILE_CONTEXT is accessed during a compile that isn't running in per-context mode.","commonSituations":"Adding COMPILE_CONTEXT to schemas for multitenancy but forgetting the required config options; running a single-tenant dev server against schemas copied from a multitenant project; accessing COMPILE_CONTEXT outside the intended compilation path.","solutions":["Define `contextToAppId` (and typically `contextToOrchestratorId`) in your cube.js configuration options.","Return a stable app id per security context so each context compiles its own schema.","If you don't need compile-time multitenancy, remove COMPILE_CONTEXT usage from the data models.","Verify the compile request actually carries a security context so contextToAppId can resolve."],"exampleFix":"// before\n// cube.js: no multitenant config, schema uses COMPILE_CONTEXT\n// after\nmodule.exports = {\n  contextToAppId: ({ securityContext }) => `APP_${securityContext?.tenantId}`,\n  contextToOrchestratorId: ({ securityContext }) => `APP_${securityContext?.tenantId}`,\n};","handlingStrategy":"validation","validationCode":"if (!options.contextToAppId && /COMPILE_CONTEXT/.test(schemaSource)) {\n  throw new Error('Schemas use COMPILE_CONTEXT; define contextToAppId in options');\n}","typeGuard":"function canUseCompileContext(opts) { return typeof opts.contextToAppId === 'function'; }","tryCatchPattern":"try { await compiler.compile(); } catch (e) { if (/COMPILE_CONTEXT can't be used/.test(e.message)) { console.error('Add contextToAppId to cube.js config or remove COMPILE_CONTEXT'); } throw e; }","preventionTips":["Pair every COMPILE_CONTEXT usage with contextToAppId config","Test multitenant compilation per security context","Keep single-tenant and multitenant schema sets separate"],"tags":["schema-compiler","multitenancy","configuration","compile-context"],"backgroundTag":"missing-context-to-app-id-config","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}