{"record":{"id":"0427455aec8aab96","repo":"cube-js/cube","slug":"pkg-dependency-not-found-please-run-this-comma","errorCode":null,"errorMessage":"${pkg} dependency not found. Please run this command from project directory.","messagePattern":"(.+?) dependency not found\\. Please run this command from project directory\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-backend-shared/src/package.ts","lineNumber":56,"sourceCode":"  pkg: string,\n  opts: RequireBaseOptions & { silent: true }\n): T | null;\n\nexport function requireFromPackage<T = unknown>(\n  pkg: string,\n  opts?: RequireBaseOptions\n): T;\n\nexport function requireFromPackage<T = unknown | null>(pkg: string, options?: RequireOptions): T | null {\n  const { basePath = process.cwd(), relative = false, silent = undefined } = options || {};\n\n  const exists = packageExists(pkg, relative, basePath);\n  if (!exists) {\n    if (silent) {\n      return null;\n    }\n\n    throw new Error(\n      `${pkg} dependency not found. Please run this command from project directory.`\n    );\n  }\n\n  if (relative) {\n    const resolvePath = require.resolve(`${pkg}`);\n\n    // eslint-disable-next-line global-require,import/no-dynamic-require\n    return require(resolvePath);\n  }\n\n  // eslint-disable-next-line global-require,import/no-dynamic-require\n  return require(path.join(basePath, 'node_modules', pkg));\n}\n\nexport function isSslKey(content: string) {\n  return content.startsWith('-----BEGIN RSA PRIVATE KEY-----') || content.startsWith('-----BEGIN EC PRIVATE KEY-----');\n}","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-backend-shared/src/package.ts#L38-L74","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["cd into your Cube project root (the directory containing package.json and node_modules) and rerun the command","Install the missing dependency: yarn add @cubejs-backend/<driver> (or the package named in the error message)","Verify node_modules/<pkg> exists in the working directory; reinstall with yarn install if node_modules is incomplete","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","Pass { silent: true } if your code should handle absence gracefully instead of throwing"],"exampleFix":"# before (thrown from ~/ or wrong dir)\n$ npx cubejs-server\nError: @cubejs-backend/server dependency not found. Please run this command from project directory.\n# after\ncd /path/to/my-cube-project && yarn install && npx cubejs-server","handlingStrategy":"validation","validationCode":"const path = require('path');\nconst fs = require('fs');\nfunction ensureProjectDeps(pkgs) {\n  const missing = pkgs.filter((p) => !fs.existsSync(path.join(process.cwd(), 'node_modules', p)));\n  if (missing.length) throw new Error(`Missing dependencies: ${missing.join(', ')}. Run from project root and yarn install.`);\n}\nensureProjectDeps(['@cubejs-backend/server', '@cubejs-backend/postgres-driver']);","typeGuard":"null","tryCatchPattern":"try {\n  const driver = requireFromPackage('@cubejs-backend/postgres-driver');\n} catch (e) {\n  if (e.message.includes('dependency not found')) {\n    console.error('Run this command from your Cube project root and install the dependency: yarn add @cubejs-backend/postgres-driver');\n    process.exit(1);\n  } else throw e;\n}","preventionTips":["Always run Cube CLI commands from the project root (directory with package.json and node_modules)","Explicitly install every driver/backend package your project needs (yarn add @cubejs-backend/<driver>)","In monorepos, add Cube packages to the correct workspace so they resolve from cwd","Use the silent: true option when your code can handle a missing package gracefully instead of crashing","Re-run yarn install after pulling changes that add new Cube backend dependencies"],"tags":["dependency","node-modules","cli","project-setup"],"backgroundTag":"module-not-found","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}