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
- 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.
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
- 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.
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
- Unable to find ${name} from path: "${value}"
- A user-defined contextToApiScopes function returns an incons
- A user-defined contextToApiScopes function returns a wrong s
- Unload is not configured. Please define CUBEJS_AWS_S3_OUTPUT
- Export bucket is not configured.
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/af2e7fdbbb80f0de.
Report an issue: GitHub.