Skip to content

Commit 18b3779

Browse files
committed
feat: update dynamic imports in SharedProjectPlugin to prevent bundler resolution issues
1 parent 0b00512 commit 18b3779

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

apps/studio/vite.config.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ export default defineConfig({
9090
transformMixedEsModules: true
9191
},
9292
rollupOptions: {
93-
external: [
94-
'@objectstack/metadata',
95-
'@objectstack/objectql',
96-
],
9793
// Suppress warnings for optional dynamic imports in runtime
9894
onwarn(warning, warn) {
9995
// Ignore unresolved import warnings for @objectstack/driver-memory

packages/runtime/src/shared-project-plugin.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ export class SharedProjectPlugin implements Plugin {
7272
if (!scopeId) {
7373
throw new Error('[SharedProjectPlugin] scopeId (projectId) required for scoped metadata');
7474
}
75-
// Dynamic import — @objectstack/metadata is a peer dep, not a hard dep of runtime
76-
const metadataMod = await import('@objectstack/metadata' as string);
75+
// Dynamic import — @objectstack/metadata is a peer dep, not a hard dep of runtime.
76+
// new Function prevents bundlers (Vite/Rolldown) from resolving this as a bare specifier.
77+
const metadataMod = await new Function('m', 'return import(m)')('@objectstack/metadata');
7778
const MetadataManager = metadataMod.MetadataManager;
7879
const driver = await _ctx.getServiceScoped<any>('driver', scopeId);
7980
const manager = new MetadataManager();
@@ -91,8 +92,9 @@ export class SharedProjectPlugin implements Plugin {
9192
if (!scopeId) {
9293
throw new Error('[SharedProjectPlugin] scopeId (projectId) required for scoped objectql');
9394
}
94-
// Dynamic import — @objectstack/objectql is a peer dep, not a hard dep of runtime
95-
const objectqlMod = await import('@objectstack/objectql' as string);
95+
// Dynamic import — @objectstack/objectql is a peer dep, not a hard dep of runtime.
96+
// new Function prevents bundlers (Vite/Rolldown) from resolving this as a bare specifier.
97+
const objectqlMod = await new Function('m', 'return import(m)')('@objectstack/objectql');
9698
const ObjectQL = objectqlMod.ObjectQL;
9799
const driver = await _ctx.getServiceScoped<any>('driver', scopeId);
98100
const ql = new ObjectQL({ logger: _ctx.logger });

0 commit comments

Comments
 (0)