cube-js/cube · error · UserError

'${fileName}' transpiling failed

Error message

'${fileName}' transpiling failed

What it means

readModuleFile transpiles the resolved module file via transpileFile; if the transpiler returns falsy (compilation produced no output, typically due to errors captured by the ErrorReporter), UserError ''${fileName}' transpiling failed' is thrown. The fileName in the message is the path relative to node_modules.

Source

Thrown at packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.ts:1047

      }
      // 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 transpiling
    }
    return moduleFileCache[absPath];
  }

  private isWhiteListedPackage(packagePath: string): boolean {
    return packagePath.indexOf('-schema') !== -1 &&
      (packagePath.indexOf('-schema') === packagePath.length - '-schema'.length);
  }
}

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Check the accompanying compiler error output for the underlying transpile error in the reported file
  2. Import a build of the package with syntax the compiler supports (CommonJS/ES2015-ish dist)
  3. Pre-bundle or transpile the dependency yourself and import the built artifact
  4. Enable allowNodeRequire to load the module via native require instead of transpiling

Example fix

// before
import { x } from 'esm-only-pkg'; // ships ESM-only syntax

// after
import { x } from 'esm-only-pkg/cjs'; // CommonJS build
Defensive patterns

Strategy: try-catch

Validate before calling

const path = require('path');
const src = fs.readFileSync(path.resolve('node_modules', modulePath), 'utf-8');
new Function(src); // throws SyntaxError if the module content is unparseable

Try / catch

try {
  await compiler.compile();
} catch (e) {
  if (String(e.message).endsWith("' transpiling failed")) {
    console.error('Module failed to transpile; check its syntax/syntax-level support:', e.message);
  }
}

Prevention

When it happens

Trigger: Importing a node_modules JS module from a data model whose content fails transpilation — syntax errors, unsupported syntax, or transpile errors reported to the ErrorReporter causing transpileFile to return null.

Common situations: Importing an ESM-only or TypeScript package into data models, a package shipping modern syntax unsupported by the compiler's Babel setup, or a corrupted/partial install in node_modules.

Related errors


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