ERR_MODULE_NOT_FOUND when running `mastra dev`

Hey folks, Have recently started getting the above when running mastra dev. We didn't get it before, and we think it's because the @cubejs-client/core package doesn't have file extensions on its imports. We run Mastra in Next with mastra dev --dir src/mastra. Any way around this one? It worked previously, so not sure if you've made any bundler changes.
17 Replies
Isaac Harris-Holt
Isaac Harris-HoltOP•3w ago
Have tried changing "type": "module" in package.json, and running with -c '--experimental-specifier-resolution=node'
Mastra Triager
Mastra Triager•3w ago
GitHub
[DISCORD:1422529954025046096] ERR_MODULE_NOT_FOUND when running `ma...
This issue was created from Discord post: https://discord.com/channels/1309558646228779139/1422529954025046096 Hey folks, Have recently started getting the above when running mastra dev. We didn&#3...
_roamin_
_roamin_•3w ago
Hi @Isaac Harris-Holt ! Could you share the full error message you're getting?
Isaac Harris-Holt
Isaac Harris-HoltOP•3w ago
Sure!
āœ“ Bundle complete
◐ [Mastra Dev] - Bundling finished, checking if restart is allowed...
◐ [Mastra Dev] - āœ… Restarting server...
↻ Restarting server...
ā—‡ Starting Mastra dev server...

node:internal/modules/run_main:123
triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/isaac/repos/medfin/medfin-fpa/node_modules/@cubejs-client/core/dist/src/ResultSet' imported from /Users/isaac/repos/medfin/medfin-fpa/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 (file:///Users/isaac/repos/medfin/medfin-fpa/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 Immediate.checkForMessages (node:internal/modules/esm/worker:141:28)
at process.processImmediate (node:internal/timers:485:21) {
code: 'ERR_MODULE_NOT_FOUND',
url: 'file:///Users/isaac/repos/medfin/medfin-fpa/node_modules/@cubejs-client/core/dist/src/ResultSet'
}

Node.js v22.17.0
āœ“ Bundle complete
◐ [Mastra Dev] - Bundling finished, checking if restart is allowed...
◐ [Mastra Dev] - āœ… Restarting server...
↻ Restarting server...
ā—‡ Starting Mastra dev server...

node:internal/modules/run_main:123
triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/isaac/repos/medfin/medfin-fpa/node_modules/@cubejs-client/core/dist/src/ResultSet' imported from /Users/isaac/repos/medfin/medfin-fpa/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 (file:///Users/isaac/repos/medfin/medfin-fpa/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 Immediate.checkForMessages (node:internal/modules/esm/worker:141:28)
at process.processImmediate (node:internal/timers:485:21) {
code: 'ERR_MODULE_NOT_FOUND',
url: 'file:///Users/isaac/repos/medfin/medfin-fpa/node_modules/@cubejs-client/core/dist/src/ResultSet'
}

Node.js v22.17.0
The head of index.js in the Cube package is:
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';
let mutexCounter = 0;
const MUTEX_ERROR = 'Mutex has been changed';
function mutexPromise(promise) {
return promise
.then((result) => result)
.catch((error) => {
if (error !== MUTEX_ERROR) {
throw error;
}
});
}
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';
let mutexCounter = 0;
const MUTEX_ERROR = 'Mutex has been changed';
function mutexPromise(promise) {
return promise
.then((result) => result)
.catch((error) => {
if (error !== MUTEX_ERROR) {
throw error;
}
});
}
I think this is what's causing the issue, but it was working previously with the same version of Cube
_roamin_
_roamin_•3w ago
There have been a few updates to our bundler. Could you try adding Cube to the transpile packages bundler config:
const mastra = new Mastra({
bundler: {
transpilePackages: ["@cubejs-client/core"]
}
})
const mastra = new Mastra({
bundler: {
transpilePackages: ["@cubejs-client/core"]
}
})
Isaac Harris-Holt
Isaac Harris-HoltOP•3w ago
No dice, I'm afraid. Cube only ship the compiled JS, if that matters Adding to externals doesn't work either (I have no idea what I'm doing - just trying stuff)
_roamin_
_roamin_•3w ago
I see, thanks for testing! Would you mind sharing a small repro example? Is it just adding the Cube package to a Mastra project?
Isaac Harris-Holt
Isaac Harris-HoltOP•3w ago
Let me check Works with a fresh installation. I've got a call now, then I'll try with a Next one I scaffolded a fresh Next app and used the one liner, and I just get the following:
WARN [2025-09-30 19:01:49.116 +0100] (Mastra): If you are using a custom instrumentation file or want to disable this warning, set the globalThis.___MASTRA_TELEMETRY___ variable to true in your instrumentation file.
WARN [2025-09-30 19:01:49.116 +0100] (Mastra): If you are using a custom instrumentation file or want to disable this warning, set the globalThis.___MASTRA_TELEMETRY___ variable to true in your instrumentation file.
Then the process exits. I've not installed cube yet Okay @Romain turns out I'm an idiot. A fresh Mastra install with the following in the index file gives the error:
import { CubeApi } from "@cubejs-client/core";
import { Mastra } from "@mastra/core/mastra";
import { LibSQLStore } from "@mastra/libsql";
import { PinoLogger } from "@mastra/loggers";
import { weatherAgent } from "./agents/weather-agent";
import { weatherWorkflow } from "./workflows/weather-workflow";

const _client = new CubeApi({
apiUrl: "http://localhost:4000",
});

export const mastra = new Mastra({
workflows: { weatherWorkflow },
agents: { weatherAgent },
storage: new LibSQLStore({
// stores telemetry, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
url: ":memory:",
}),
logger: new PinoLogger({
name: "Mastra",
level: "info",
}),
});
import { CubeApi } from "@cubejs-client/core";
import { Mastra } from "@mastra/core/mastra";
import { LibSQLStore } from "@mastra/libsql";
import { PinoLogger } from "@mastra/loggers";
import { weatherAgent } from "./agents/weather-agent";
import { weatherWorkflow } from "./workflows/weather-workflow";

const _client = new CubeApi({
apiUrl: "http://localhost:4000",
});

export const mastra = new Mastra({
workflows: { weatherWorkflow },
agents: { weatherAgent },
storage: new LibSQLStore({
// stores telemetry, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
url: ":memory:",
}),
logger: new PinoLogger({
name: "Mastra",
level: "info",
}),
});
I'd forgotten to actually import the library previously šŸ˜…
_roamin_
_roamin_•3w ago
Don't worry, we're all idiots šŸ˜‚ Thanks, I can repro, too! I'll add the code you shared to the github issue
LekoArts
LekoArts•2w ago
I added a note to the issue (https://github.com/mastra-ai/mastra/issues/8297#issuecomment-3388803351) to tell you how to workaround this bug in cubejs
GitHub
[DISCORD:1422529954025046096] ERR_MODULE_NOT_FOUND when running `ma...
This issue was created from Discord post: https://discord.com/channels/1309558646228779139/1422529954025046096 Hey folks, Have recently started getting the above when running mastra dev. We didn&#3...
Isaac Harris-Holt
Isaac Harris-HoltOP•2w ago
What about other modules? Am I going to have to do the same if I run into the same issues elsewhere?
LekoArts
LekoArts•6d ago
Yes, if the module is invalid it needs to be fixed upstream
Isaac Harris-Holt
Isaac Harris-HoltOP•6d ago
That's not always feasible. Some of the libraries that'll be causing this problem may take months to get to an issue, especially something as large as migrating to ESM. I appreciate it's extra work for you folks, but it's making the Mastra playground unusable when pulling in dependencies that haven't made the switch Cube, in particular, is something that'll be used by a large number of folks working with agents
LekoArts
LekoArts•6d ago
It's not about libraries switching to ESM, Mastra supports CommonJS packages just fine. It's that the ESM version of CubeJS is invalid. Then when Mastra tries to just run node index.mjs with the cubejs import, it fails But let me double check internally if transpilePackages couldn't handle this alternatively
Isaac Harris-Holt
Isaac Harris-HoltOP•6d ago
Thanks šŸ™Œ It worked previously, so it should be able to
LekoArts
LekoArts•6d ago
We spent some time looking at it today but it's not an easy fix. And with other priorities not high on our list of things to fix (since it's the fault of an upstream package). So can't give you an ETA when that might be fixed
Isaac Harris-Holt
Isaac Harris-HoltOP•5d ago
Alrighty, no worries. Thanks for taking a look

Did you find this page helpful?