Monorepo transpile packages does not appear to be working.

I have an npm monorepo that uses a shared DAO package to facilitate data connections to the db. Importing the package into the mastra server 'app' causes the build job to fail to import. The dev server works fine. Here is the error message:
Mastra Build failed
error: {
"message": "Failed to analyze Mastra application: \u0000virtual:#virtual-@intervalai/sb (1:9): \"CustomerDao\" is not exported by \"../../packages/supabaseDAO/dist/index.js\", imported by \"\u0000virtual:#virtual-@intervalai/sb\".",
"details": {
"message": "Failed to analyze Mastra application: \u0000virtual:#virtual-@intervalai/sb (1:9): \"CustomerDao\" is not exported by \"../../packages/supabaseDAO/dist/index.js\", imported by \"\u0000virtual:#virtual-@intervalai/sb\".",
"domain": "DEPLOYER",
"category": "SYSTEM",
"details": {}
},
"code": "DEPLOYER_BUNDLER_ANALYZE_FAILED"
}
Mastra Build failed
error: {
"message": "Failed to analyze Mastra application: \u0000virtual:#virtual-@intervalai/sb (1:9): \"CustomerDao\" is not exported by \"../../packages/supabaseDAO/dist/index.js\", imported by \"\u0000virtual:#virtual-@intervalai/sb\".",
"details": {
"message": "Failed to analyze Mastra application: \u0000virtual:#virtual-@intervalai/sb (1:9): \"CustomerDao\" is not exported by \"../../packages/supabaseDAO/dist/index.js\", imported by \"\u0000virtual:#virtual-@intervalai/sb\".",
"domain": "DEPLOYER",
"category": "SYSTEM",
"details": {}
},
"code": "DEPLOYER_BUNDLER_ANALYZE_FAILED"
}
2 Replies
Aaron Farr
Aaron FarrOP2w ago
I do not know very much about rollup, or debugging really, but after hours of peppering console.logs all over the mastra deploy files, I have determined that this line in the buildExternalDependencies function is the one throwing the error.
const bundler = await rollup({
logLevel: "silent",
input: Array.from(virtualDependencies.entries()).reduce(
(acc, [dep, virtualDep]) => {
acc[virtualDep.name] = `#virtual-${dep}`;
return acc;
},
{}
),
external: externals,
treeshake: "smallest",
plugins: getInputPlugins2(virtualDependencies, {
transpilePackages: packagesToTranspile,
workspaceMap,
bundlerOptions,
rootDir
})
});
const bundler = await rollup({
logLevel: "silent",
input: Array.from(virtualDependencies.entries()).reduce(
(acc, [dep, virtualDep]) => {
acc[virtualDep.name] = `#virtual-${dep}`;
return acc;
},
{}
),
external: externals,
treeshake: "smallest",
plugins: getInputPlugins2(virtualDependencies, {
transpilePackages: packagesToTranspile,
workspaceMap,
bundlerOptions,
rootDir
})
});
The virtual dependency array that is reduced here returns the same 'name' property pattern for all of the packages except for the customerDAO.
'@mastra/memory' => {
name: 'apps/interval-mastra/.mastra/.build/@mastra-memory',
virtual: "export { Memory } from '@mastra/memory';"
},
'@intervalai/sb' => {
name: 'packages/supabaseDAO/node_modules/.cache/@intervalai-sb',
virtual: "export { CustomerDao } from '@intervalai/sb';"
},
'@mastra/core/tools' => {
name: 'apps/interval-mastra/.mastra/.build/@mastra-core-tools',
virtual: "export { createTool, isVercelTool, Tool } from '@mastra/core/tools';"
'@mastra/memory' => {
name: 'apps/interval-mastra/.mastra/.build/@mastra-memory',
virtual: "export { Memory } from '@mastra/memory';"
},
'@intervalai/sb' => {
name: 'packages/supabaseDAO/node_modules/.cache/@intervalai-sb',
virtual: "export { CustomerDao } from '@intervalai/sb';"
},
'@mastra/core/tools' => {
name: 'apps/interval-mastra/.mastra/.build/@mastra-core-tools',
virtual: "export { createTool, isVercelTool, Tool } from '@mastra/core/tools';"
(The customer dao comes from another directory. ALL of the packages are in the mastra/.build directory but this one) I have no idea if any of this information is relevant. The only concrete fact I have been able to confirm is that I am too dumb to figure this out. OK, updates. I was able to successfully build! I edited the buildExternalDependencies in order to skip adding the '#virtual-' prefix to the property in the inputs array for my customerDao dependency:
input: Array.from(virtualDependencies.entries()).reduce(
(acc, [dep, virtualDep]) => {
if(virtualDep.name.includes('ai-sb')){
console.log('virtualDep', virtualDep)
acc[virtualDep.name] = dep;
}else{
acc[virtualDep.name] = `#virtual-${dep}`;
}
return acc;
},
input: Array.from(virtualDependencies.entries()).reduce(
(acc, [dep, virtualDep]) => {
if(virtualDep.name.includes('ai-sb')){
console.log('virtualDep', virtualDep)
acc[virtualDep.name] = dep;
}else{
acc[virtualDep.name] = `#virtual-${dep}`;
}
return acc;
},
This change made everything work. IDK if there is some configuration I did wrong that caused this? Also, removing the package from the transpilePackages list did not affect anything. My original assumption about transpilePackages being the root of the problem was wrong It would also appear that simply excluding the package from the virtualDependency array does not properly fix the problem, as that prevents the package from importing properly
Mastra Triager
GitHub
[DISCORD:1425901393260314695] Monorepo transpile packages does not ...
This issue was created from Discord post: https://discord.com/channels/1309558646228779139/1425901393260314695 I have an npm monorepo that uses a shared DAO package to facilitate data connections t...

Did you find this page helpful?