Skip to content

Commit

Permalink
Windows Fix (#352) (#354)
Browse files Browse the repository at this point in the history
In ESM, modules must be imported [as
URLs](#352). This is enforced
more strictly on Windows. Thus, we now import `operations.js` as a file
URL.

Co-authored-by: Peter Kraft <peter.kraft@dbos.dev>
  • Loading branch information
qianl15 and kraftp committed Mar 21, 2024
1 parent e0def5b commit f341866
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/dbos-runtime/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isObject } from 'lodash';
import { DBOSFailLoadOperationsError } from '../error';
import path from 'node:path';
import { Server } from 'http';
import { pathToFileURL } from 'url';

interface ModuleExports {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -37,7 +38,7 @@ export class DBOSRuntime {
if (classes.length === 0) {
throw new DBOSFailLoadOperationsError("operations not found");
}
await this.dbosExec.init(...classes);
await this.dbosExec.init(...classes);
const server = new DBOSHttpServer(this.dbosExec)
this.servers = await server.listen(this.runtimeConfig.port);
this.dbosExec.logRegisteredHTTPUrls();
Expand All @@ -62,8 +63,8 @@ export class DBOSRuntime {
const operations = path.isAbsolute(entrypoint) ? entrypoint : path.join(process.cwd(), entrypoint);
let exports: ModuleExports;
if (fs.existsSync(operations)) {
/* eslint-disable-next-line @typescript-eslint/no-var-requires */
exports = (await import(operations)) as Promise<ModuleExports>;
const operationsURL = pathToFileURL(operations).href;
exports = (await import(operationsURL)) as Promise<ModuleExports>;
} else {
throw new DBOSFailLoadOperationsError(`Failed to load operations from the entrypoint ${entrypoint}`);
}
Expand Down Expand Up @@ -93,4 +94,4 @@ export class DBOSRuntime {
}
await this.dbosExec?.destroy();
}
}
}

0 comments on commit f341866

Please sign in to comment.