cube-js/cube · error · UserError
Path '${absPath.replace(nodeModulesPath + '/', '')}' not fou
Error message
Path '${absPath.replace(nodeModulesPath + '/', '')}' not found What it means
After whitelist validation the compiler appends '.js' if needed and checks that the module file exists on disk under node_modules. If it does not, and allowNodeRequire is false, it throws UserError 'Path '...' not found' naming the path relative to node_modules.
Source
Thrown at packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.ts:1031
if (this.allowNodeRequire) {
return null;
}
throw new UserError(`Package '${packagePath}' not found`);
}
if (fs.existsSync(absPath)) {
const stat = fs.lstatSync(absPath);
if (stat.isDirectory()) {
absPath = path.resolve(absPath, 'index.js');
}
}
// eslint-disable-next-line prefer-template
absPath = path.extname(absPath) !== '.js' ? absPath + '.js' : absPath;
if (!fs.existsSync(absPath)) {
if (this.allowNodeRequire) {
return null;
}
// eslint-disable-next-line prefer-template
throw new UserError(`Path '${absPath.replace(nodeModulesPath + '/', '')}' not found`);
}
return this.readModuleFile(absPath, errorsReport);
}
private readModuleFile(absPath: string, errorsReport: ErrorReporter) {
const nodeModulesPath = path.resolve('node_modules');
if (!moduleFileCache[absPath]) {
const content = fs.readFileSync(absPath, 'utf-8');
// eslint-disable-next-line prefer-template
const fileName = absPath.replace(nodeModulesPath + '/', '');
const transpiled = this.transpileFile(
{ fileName, content, isModule: true },
errorsReport
);
if (!transpiled) {
throw new UserError(`'${fileName}' transpiling failed`);
}
moduleFileCache[absPath] = transpiled; // TODO isolated transpilingView on GitHub (pinned to 7d981676b3)
Solutions
- Verify the file exists: node -e "require.resolve('<modulePath>')" in the project root
- Fix the import to a valid subpath or the package root
- Install/reinstall the dependency so the referenced file exists
- Enable allowNodeRequire to fall back to native require resolution
Example fix
// before
import { deep } from 'lodash/internal';
// after
import { cloneDeep } from 'lodash'; Defensive patterns
Strategy: validation
Validate before calling
const fs = require('fs');
const path = require('path');
function moduleFileExists(modulePath) {
let p = path.resolve('node_modules', modulePath);
if (fs.existsSync(p) && fs.lstatSync(p).isDirectory()) p = path.join(p, 'index.js');
if (path.extname(p) !== '.js') p += '.js';
return fs.existsSync(p);
} Try / catch
try {
await compiler.compile();
} catch (e) {
const m = String(e.message).match(/Path '(.+)' not found/);
if (m) console.error(`Missing module file: node_modules/${m[1]}`);
} Prevention
- Avoid deep imports into package internals; use documented entry points
- Pin dependency versions so subpaths do not disappear on upgrade
- Verify imports with require.resolve() locally before deploying
When it happens
Trigger: Importing a subpath of a package that does not exist (e.g. 'lodash/deep' instead of 'lodash'), a package installed without the referenced file, or a directory lacking index.js.
Common situations: Package version differences where the subpath moved or was removed, deep imports into packages that only expose main entry or exports map entries, or missing devDependency in the deployment image.
Related errors
- '${modulePath}' restricted
- '${modulePath}' is incorrect
- Package '${packagePath}' not found
- Unable to find package.json file in current working director
- Unable to find ${name} from path: "${value}"
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/a6da372107f171cf.
Report an issue: GitHub.