{"record":{"id":"f70c9ac55fa80199","repo":"cube-js/cube","slug":"modulepath-is-incorrect","errorCode":null,"errorMessage":"'${modulePath}' is incorrect","messagePattern":"'(.+?)' is incorrect","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.ts","lineNumber":1010,"sourceCode":"    }\n\n    const nodeModulesPath = path.resolve('node_modules');\n    let absPath = currentFile.isModule ?\n      path.resolve('node_modules', path.dirname(currentFile.fileName), modulePath) :\n      path.resolve('node_modules', modulePath);\n\n    if (!absPath.startsWith(nodeModulesPath)) {\n      if (this.allowNodeRequire) {\n        return null;\n      }\n      throw new UserError(`'${modulePath}' restricted`);\n    }\n    const packagePath = absPath.replace(nodeModulesPath, '').split('/').filter(s => !!s)[0];\n    if (!packagePath) {\n      if (this.allowNodeRequire) {\n        return null;\n      }\n      throw new UserError(`'${modulePath}' is incorrect`);\n    }\n    if (!this.isWhiteListedPackage(packagePath)) {\n      if (this.allowNodeRequire) {\n        return null;\n      }\n      throw new UserError(`Package '${packagePath}' not found`);\n    }\n    if (fs.existsSync(absPath)) {\n      const stat = fs.lstatSync(absPath);\n      if (stat.isDirectory()) {\n        absPath = path.resolve(absPath, 'index.js');\n      }\n    }\n    // eslint-disable-next-line prefer-template\n    absPath = path.extname(absPath) !== '.js' ? absPath + '.js' : absPath;\n    if (!fs.existsSync(absPath)) {\n      if (this.allowNodeRequire) {\n        return null;","sourceCodeStart":992,"sourceCodeEnd":1028,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.ts#L992-L1028","documentation":"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.","triggerScenarios":"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.","commonSituations":"Leftover empty require/import statements, template literals that interpolate to an empty string, or misconfigured dynamic import specifiers in generated schemas.","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"],"exampleFix":"// before\nconst pkg = require(name); // name === ''\n\n// after\nconst pkg = require('lodash');","handlingStrategy":"validation","validationCode":"function isValidModuleSpecifier(modulePath) {\n  return typeof modulePath === 'string' && modulePath.trim() !== '' && modulePath !== '.' && modulePath !== '/';\n}","typeGuard":null,"tryCatchPattern":"try {\n  await compiler.compile();\n} catch (e) {\n  if (String(e.message).endsWith(\"' is incorrect\")) {\n    console.error('Empty or malformed module specifier in data model:', e.message);\n  }\n}","preventionTips":["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"],"tags":["module-resolution","schema-compiler","validation"],"backgroundTag":"invalid-module-specifier","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}