cube-js/cube · error · Error

${pkg} dependency not found. Please run this command from pr

Error message

${pkg} dependency not found. Please run this command from project directory.

What it means

requireFromPackage() resolves and requires a module from the user's project directory (process.cwd()/node_modules or a given basePath). If the package cannot be found there and silent mode is not enabled, it throws this error telling the developer to run the Cube CLI command from the project root where dependencies are installed.

Source

Thrown at packages/cubejs-backend-shared/src/package.ts:56

  pkg: string,
  opts: RequireBaseOptions & { silent: true }
): T | null;

export function requireFromPackage<T = unknown>(
  pkg: string,
  opts?: RequireBaseOptions
): T;

export function requireFromPackage<T = unknown | null>(pkg: string, options?: RequireOptions): T | null {
  const { basePath = process.cwd(), relative = false, silent = undefined } = options || {};

  const exists = packageExists(pkg, relative, basePath);
  if (!exists) {
    if (silent) {
      return null;
    }

    throw new Error(
      `${pkg} dependency not found. Please run this command from project directory.`
    );
  }

  if (relative) {
    const resolvePath = require.resolve(`${pkg}`);

    // eslint-disable-next-line global-require,import/no-dynamic-require
    return require(resolvePath);
  }

  // eslint-disable-next-line global-require,import/no-dynamic-require
  return require(path.join(basePath, 'node_modules', pkg));
}

export function isSslKey(content: string) {
  return content.startsWith('-----BEGIN RSA PRIVATE KEY-----') || content.startsWith('-----BEGIN EC PRIVATE KEY-----');
}

View on GitHub (pinned to 7d981676b3)

Solutions

  1. cd into your Cube project root (the directory containing package.json and node_modules) and rerun the command
  2. Install the missing dependency: yarn add @cubejs-backend/<driver> (or the package named in the error message)
  3. Verify node_modules/<pkg> exists in the working directory; reinstall with yarn install if node_modules is incomplete
  4. In monorepos/workspaces, ensure the package is added to the workspace that is the cwd, or pass an explicit basePath where the package is installed
  5. Pass { silent: true } if your code should handle absence gracefully instead of throwing

Example fix

# before (thrown from ~/ or wrong dir)
$ npx cubejs-server
Error: @cubejs-backend/server dependency not found. Please run this command from project directory.
# after
cd /path/to/my-cube-project && yarn install && npx cubejs-server
Defensive patterns

Strategy: validation

Validate before calling

const path = require('path');
const fs = require('fs');
function ensureProjectDeps(pkgs) {
  const missing = pkgs.filter((p) => !fs.existsSync(path.join(process.cwd(), 'node_modules', p)));
  if (missing.length) throw new Error(`Missing dependencies: ${missing.join(', ')}. Run from project root and yarn install.`);
}
ensureProjectDeps(['@cubejs-backend/server', '@cubejs-backend/postgres-driver']);

Type guard

null

Try / catch

try {
  const driver = requireFromPackage('@cubejs-backend/postgres-driver');
} catch (e) {
  if (e.message.includes('dependency not found')) {
    console.error('Run this command from your Cube project root and install the dependency: yarn add @cubejs-backend/postgres-driver');
    process.exit(1);
  } else throw e;
}

Prevention

When it happens

Trigger: Running a Cube CLI command (scaffold, driver install, server start) outside the project directory, or in a directory where the required package (e.g. @cubejs-backend/server, a database driver like @cubejs-backend/postgres-driver, or a scaffolding template) is not installed in node_modules; also when basePath points to a directory without node_modules.

Common situations: Running `npx cubejs-server` or driver commands from home directory instead of project root; forgetting to `yarn add`/`npm install` a required driver package; monorepo setups where node_modules hoisting hides the package from basePath; deleted or incomplete node_modules.

Related errors


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