Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Support ES6 syntax for botkit features #1854

Merged
merged 2 commits into from
Jan 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/botkit/src/core.ts
Original file line number Diff line number Diff line change
@@ -1108,7 +1108,15 @@ export class Botkit {
*/
public loadModule(p: string): void {
debug('Load Module:', p);
require(p)(this);
const module = require(p);
// Handle both CJS `module.exports` and ESM `export default` syntax.
if (typeof module === 'function') {
module(this);
} else if (module && typeof module.default === 'function') {
module.default(this);
} else {
throw new Error(`Failed to load '${p}', did you export a function?`);
}
}

/**