Module Resolution Failure cubejs-client
Describe the bug A clear and concise description of what the bug is.
When importing Cube within a Mastra workflow I get a
To Reproduce Steps to reproduce the behavior:
- Make a Mastra agent workflow that imports cubejs-client
- Run the project
- You will see the below error
Other modules import fine so the module import issue is specifically related to cubejs clinet
Expected behaviour Import Resolution to complete
./node_modules/@cubejs-client/core/dist/src/index.js
at finalizeResolution (node:internal/modules/esm/resolve:275:11)
at moduleResolve (node:internal/modules/esm/resolve:860:10)
at defaultResolve (node:internal/modules/esm/resolve:984:11)
at nextResolve (node:internal/modules/esm/hooks:748:28)
at resolve (./node_modules/mastra/dist/commands/dev/telemetry-resolver.js:4:12)
at nextResolve (node:internal/modules/esm/hooks:748:28)
at Hooks.resolve (node:internal/modules/esm/hooks:240:30)
at handleMessage (node:internal/modules/esm/worker:199:24)
at checkForMessages (node:internal/modules/esm/worker:141:28)
at process.<anonymous> (node:internal/modules/esm/worker:160:5) {
code: 'ERR_MODULE_NOT_FOUND',
url: './node_modules/@cubejs-client/core/dist/src/ResultSet'
}
Node.js v22.17.0
If I go into @cubejs-client/core/dist/src/index.js and add .js to some of the imports it resolves some issues however this is not sustainable for the full module
This is due to the Cube client code not containing valid ESM. I'm happy to make a PR if the maintainers are open to it.
Would be really great to fix this. Should be a one-line fix!
TypeScript cannot resolve types with Node16/NodeNext module resolution
Problem
When using TypeScript with moduleResolution: "Node16" or "NodeNext", TypeScript cannot find type definitions for @cubejs-client/core v1.5.10, even though the types exist.
Error message:
Could not find a declaration file for module '@cubejs-client/core'.
'.../cubejs-client-core.cjs.js' implicitly has an 'any' type.
Root Cause
The package.json has:
- ✅
"typings": "dist/src/index.d.ts"(works with oldernoderesolution) - ✅ Type definition files exist in
dist/src/index.d.ts - ❌
"exports"field missing a"types"entry
When using Node16/NodeNext module resolution, TypeScript only looks at the exports field and ignores the typings field. Since exports doesn't include a types entry, TypeScript cannot find the type definitions.
Current package.json exports
"exports": {
"import": "./dist/src/index.js",
"require": "./dist/cubejs-client-core.cjs.js"
}
Expected Fix
Add a types entry to the exports field:
"exports": {
+ "types": "./dist/src/index.d.ts",
"import": "./dist/src/index.js",
"require": "./dist/cubejs-client-core.cjs.js"
}
Environment
- TypeScript: 5.x
- Module Resolution:
Node16orNodeNext - Package Version: 1.5.10
Workaround
Users can downgrade to moduleResolution: "node", but this loses the stricter module resolution benefits of Node16/NodeNext.
Can a maintainer push this fix across the finish line? https://github.com/cube-js/cube/pull/10209
It was merged, so please use v1.5.11+ or, better, v1.6.x.
@igorlukanin unfortunately this issue is still present in both versions. That PR doesn't solve the core issue, which is missing file extensions on the imports.
Please reopen this issue.
For reference, this is the patch we've applied to 1.5.3 via bun patch to get it working:
diff --git a/dist/src/HttpTransport.js b/dist/src/HttpTransport.js
index 91270da4eb111898ed208c1478645c437fdbfbcb..c513cf68ff8ecc2cf26bbd1d6c92df95ec2c8e39 100644
--- a/dist/src/HttpTransport.js
+++ b/dist/src/HttpTransport.js
@@ -1,6 +1,6 @@
import fetch from 'cross-fetch';
import 'url-search-params-polyfill';
-import { responseChunks } from './streaming';
+import { responseChunks } from './streaming.js';
/**
* Default transport implementation.
*/
diff --git a/dist/src/ResultSet.js b/dist/src/ResultSet.js
index aec804d4186f8fb8438affa234aaffd6f631e6ea..de60f23050423a46d0a94cfecd20ebc4ea58268c 100644
--- a/dist/src/ResultSet.js
+++ b/dist/src/ResultSet.js
@@ -1,7 +1,7 @@
import dayjs from 'dayjs';
import { groupBy, pipe, fromPairs, uniq, map, dropLast, equals, reduce, minBy, maxBy, clone, mergeDeepLeft, flatten, } from 'ramda';
-import { aliasSeries } from './utils';
-import { DateRegex, dayRange, internalDayjs, isPredefinedGranularity, LocalDateRegex, TIME_SERIES, timeSeriesFromCustomInterval } from './time';
+import { aliasSeries } from './utils.js';
+import { DateRegex, dayRange, internalDayjs, isPredefinedGranularity, LocalDateRegex, TIME_SERIES, timeSeriesFromCustomInterval } from './time.js';
const groupByToPairs = function groupByToPairsImpl(keyFn) {
const acc = new Map();
return (data) => {
diff --git a/dist/src/index.js b/dist/src/index.js
index 8024e7e30b85db1e1bac52a61cd85bc0c7ccf908..906ed9514885559727d09a936871dd07e79e7531 100644
--- a/dist/src/index.js
+++ b/dist/src/index.js
@@ -1,10 +1,10 @@
import { v4 as uuidv4 } from 'uuid';
-import ResultSet from './ResultSet';
-import SqlQuery from './SqlQuery';
-import Meta from './Meta';
-import ProgressResult from './ProgressResult';
-import HttpTransport from './HttpTransport';
-import RequestError from './RequestError';
+import ResultSet from './ResultSet.js';
+import SqlQuery from './SqlQuery.js';
+import Meta from './Meta.js';
+import ProgressResult from './ProgressResult.js';
+import HttpTransport from './HttpTransport.js';
+import RequestError from './RequestError.js';
let mutexCounter = 0;
const MUTEX_ERROR = 'Mutex has been changed';
function mutexPromise(promise) {
@@ -541,12 +541,12 @@ class CubeApi {
}
export default (apiToken, options) => new CubeApi(apiToken, options);
export { CubeApi };
-export { default as Meta } from './Meta';
-export { default as SqlQuery } from './SqlQuery';
-export { default as RequestError } from './RequestError';
-export { default as ProgressResult } from './ProgressResult';
-export { default as ResultSet } from './ResultSet';
-export * from './HttpTransport';
-export * from './utils';
-export * from './time';
-export * from './types';
+export { default as Meta } from './Meta.js';
+export { default as SqlQuery } from './SqlQuery.js';
+export { default as RequestError } from './RequestError.js';
+export { default as ProgressResult } from './ProgressResult.js';
+export { default as ResultSet } from './ResultSet.js';
+export * from './HttpTransport.js';
+export * from './utils.js';
+export * from './time.js';
+export * from './types.js';
diff --git a/dist/src/index.umd.js b/dist/src/index.umd.js
index 1fc70e25b8ea3d822e04aa6a73f874f28b00f13f..9951cb91577de15c3b06eb6741ab6a0a132d8a81 100644
--- a/dist/src/index.umd.js
+++ b/dist/src/index.umd.js
@@ -1,4 +1,4 @@
-import cube, * as clientCoreExports from './index';
+import cube, * as clientCoreExports from './index.js';
const cubeAll = cube;
Object.keys(clientCoreExports).forEach((key) => {
cubeAll[key] = clientCoreExports[key];
diff --git a/dist/src/time.js b/dist/src/time.js
index 4a84e61fec3cfa09fb5636e1146689f662b18b99..bb689cd9f00c0e545acc170bcdfb0747069d2cae 100644
--- a/dist/src/time.js
+++ b/dist/src/time.js
@@ -1,8 +1,8 @@
import dayjs from 'dayjs';
-import quarterOfYear from 'dayjs/plugin/quarterOfYear';
-import duration from 'dayjs/plugin/duration';
-import isoWeek from 'dayjs/plugin/isoWeek';
-import en from 'dayjs/locale/en';
+import quarterOfYear from 'dayjs/plugin/quarterOfYear.js';
+import duration from 'dayjs/plugin/duration.js';
+import isoWeek from 'dayjs/plugin/isoWeek.js';
+import en from 'dayjs/locale/en.js';
dayjs.extend(quarterOfYear);
dayjs.extend(duration);
dayjs.extend(isoWeek);
diff --git a/dist/src/utils.js b/dist/src/utils.js
index da7105ecb87cc49fe7cbc07dbcff5f5abe0a2c52..496de30773844ee2e0f3335ea7ad2d4b0afcfe8c 100644
--- a/dist/src/utils.js
+++ b/dist/src/utils.js
@@ -1,5 +1,5 @@
import { clone, equals, fromPairs, indexBy, prop, toPairs } from 'ramda';
-import { DEFAULT_GRANULARITY } from './time';
+import { DEFAULT_GRANULARITY } from './time.js';
export function removeEmptyQueryFields(_query) {
const query = _query || {};
return fromPairs(toPairs(query).flatMap(([key, value]) => {