{"record":{"id":"af2e7fdbbb80f0de","repo":"cube-js/cube","slug":"unable-to-find-package-json-file-in-current-workin","errorCode":null,"errorMessage":"Unable to find package.json file in current working directory: ${process.cwd()}","messagePattern":"Unable to find package\\.json file in current working directory: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-backend-maven/src/maven.ts","lineNumber":167,"sourceCode":"\n  throw new Error(\n    `Unable to resolve maven dependencies, mvn exited with: \"${mvnOutput.status}\" code`\n  );\n}\n\nexport async function resolveDependencies(dependecies: MavenDependency[], options: ResolveOptions) {\n  const pathToPom = path.resolve(os.tmpdir(), 'cubejs-pom.xml');\n\n  fs.writeFileSync(pathToPom, generateXml(dependecies));\n\n  await installDependencies(pathToPom, options);\n}\n\nexport function getDependenciesFromPackage(): MavenDependency[] {\n  const pathToLock = path.join(process.cwd(), 'package.json');\n\n  if (!fs.existsSync(pathToLock)) {\n    throw new Error(\n      `Unable to find package.json file in current working directory: ${process.cwd()}`\n    );\n  }\n\n  const content = fs.readFileSync(pathToLock, {\n    encoding: 'utf-8'\n  });\n\n  const pkg = JSON.parse(content);\n  if (pkg) {\n    if (pkg.java && pkg.java.dependencies) {\n      return pkg.java.dependencies;\n    }\n  }\n\n  return [];\n}\n","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-backend-maven/src/maven.ts#L149-L185","documentation":"getDependenciesFromPackage reads package.json from the current working directory to determine which Maven dependencies to resolve. If no package.json exists in process.cwd(), the function throws, since it cannot infer the project's dependencies.","triggerScenarios":"Calling getDependenciesFromPackage() while the process cwd is not a Node project root — e.g. running the server from a different directory, a global install, or a container started with the wrong workdir.","commonSituations":"Starting cubejs-server from a directory above/below the project; Docker images with a wrong WORKDIR; running via npx/global CLI outside a project folder; renamed or deleted package.json.","solutions":["Run the Cube process from the project directory that contains package.json (cd into the project root).","Fix the WORKDIR / working-directory setting in your Dockerfile or process manager.","If invoking programmatically, call process.chdir(projectRoot) before resolving maven dependencies."],"exampleFix":"// before (wrong cwd)\n$ cd ~ && cubejs server\n\n// after\n$ cd ~/my-cube-project && cubejs server","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nconst path = require('path');\nif (!fs.existsSync(path.join(process.cwd(), 'package.json'))) {\n  throw new Error(`Run from the project root containing package.json (cwd: ${process.cwd()})`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always start the Cube process from the directory containing package.json.","Set WORKDIR correctly in Dockerfiles and cwd in process managers (pm2, systemd).","Guard the boot sequence: check for package.json before initializing maven-backed drivers."],"tags":["filesystem","configuration","cwd","package-json"],"backgroundTag":"missing-package-json","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}