cube-js/cube · error

Unable to find package.json file in current working director

Error message

Unable to find package.json file in current working directory: ${process.cwd()}

What it means

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.

Source

Thrown at packages/cubejs-backend-maven/src/maven.ts:167

  throw new Error(
    `Unable to resolve maven dependencies, mvn exited with: "${mvnOutput.status}" code`
  );
}

export async function resolveDependencies(dependecies: MavenDependency[], options: ResolveOptions) {
  const pathToPom = path.resolve(os.tmpdir(), 'cubejs-pom.xml');

  fs.writeFileSync(pathToPom, generateXml(dependecies));

  await installDependencies(pathToPom, options);
}

export function getDependenciesFromPackage(): MavenDependency[] {
  const pathToLock = path.join(process.cwd(), 'package.json');

  if (!fs.existsSync(pathToLock)) {
    throw new Error(
      `Unable to find package.json file in current working directory: ${process.cwd()}`
    );
  }

  const content = fs.readFileSync(pathToLock, {
    encoding: 'utf-8'
  });

  const pkg = JSON.parse(content);
  if (pkg) {
    if (pkg.java && pkg.java.dependencies) {
      return pkg.java.dependencies;
    }
  }

  return [];
}

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Run the Cube process from the project directory that contains package.json (cd into the project root).
  2. Fix the WORKDIR / working-directory setting in your Dockerfile or process manager.
  3. If invoking programmatically, call process.chdir(projectRoot) before resolving maven dependencies.

Example fix

// before (wrong cwd)
$ cd ~ && cubejs server

// after
$ cd ~/my-cube-project && cubejs server
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
const path = require('path');
if (!fs.existsSync(path.join(process.cwd(), 'package.json'))) {
  throw new Error(`Run from the project root containing package.json (cwd: ${process.cwd()})`);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/af2e7fdbbb80f0de. Report an issue: GitHub.