cube-js/cube · error · UserError
'${modulePath}' is incorrect
Error message
'${modulePath}' is incorrect What it means
After resolving the module path under node_modules, the compiler derives the top-level package name. If the path yields no package segment (empty packagePath), the import is deemed invalid and UserError ''${modulePath}' is incorrect' is thrown (unless allowNodeRequire is set). This guards against malformed or degenerate module specifiers.
Source
Thrown at packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.ts:1010
}
const nodeModulesPath = path.resolve('node_modules');
let absPath = currentFile.isModule ?
path.resolve('node_modules', path.dirname(currentFile.fileName), modulePath) :
path.resolve('node_modules', modulePath);
if (!absPath.startsWith(nodeModulesPath)) {
if (this.allowNodeRequire) {
return null;
}
throw new UserError(`'${modulePath}' restricted`);
}
const packagePath = absPath.replace(nodeModulesPath, '').split('/').filter(s => !!s)[0];
if (!packagePath) {
if (this.allowNodeRequire) {
return null;
}
throw new UserError(`'${modulePath}' is incorrect`);
}
if (!this.isWhiteListedPackage(packagePath)) {
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;View on GitHub (pinned to 7d981676b3)
Solutions
- Fix the import specifier so it names a real package or file (e.g. 'lodash' not '' or '.')
- Remove the empty/dynamic import if it is dead code
- Enable allowNodeRequire if this import is intentional and handled natively
Example fix
// before
const pkg = require(name); // name === ''
// after
const pkg = require('lodash'); Defensive patterns
Strategy: validation
Validate before calling
function isValidModuleSpecifier(modulePath) {
return typeof modulePath === 'string' && modulePath.trim() !== '' && modulePath !== '.' && modulePath !== '/';
} Try / catch
try {
await compiler.compile();
} catch (e) {
if (String(e.message).endsWith("' is incorrect")) {
console.error('Empty or malformed module specifier in data model:', e.message);
}
} Prevention
- Lint data model files for empty require()/import arguments
- Avoid building import specifiers via string interpolation of possibly-empty variables
- Run schema compilation in CI to catch malformed imports early
When it happens
Trigger: Importing '' or '.' from a data model module such that path.resolve('node_modules', modulePath) equals node_modules itself and the first path segment after node_modules is empty.
Common situations: Leftover empty require/import statements, template literals that interpolate to an empty string, or misconfigured dynamic import specifiers in generated schemas.
Related errors
- '${modulePath}' restricted
- Package '${packagePath}' not found
- Path '${absPath.replace(nodeModulesPath + '/', '')}' not fou
- Can't parse date: '${from}'
- Can't parse date: '${to}'
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/f70c9ac55fa80199.
Report an issue: GitHub.