Skip to content

Commit 8eaf19b

Browse files
committed
Set compiler to use commonjs
- cosmiconfig does not support esm.
1 parent d71bc4a commit 8eaf19b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/loader.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import { TypeScriptCompileError } from "./typescript-compile-error";
55
export function TypeScriptLoader(options?: RegisterOptions): Loader {
66
return (path: string, content: string) => {
77
try {
8-
register(options).compile(content, path);
8+
// cosmiconfig requires the transpiled configuration to be CJS
9+
register({ ...options, compilerOptions: { module: "commonjs" } }).compile(
10+
content,
11+
path
12+
);
913
const result = require(path);
1014

11-
/**
12-
* `default` is used when exporting using export default, some modules
13-
* may still use `module.exports` or if in TS `export = `
14-
*/
15+
// `default` is used when exporting using export default, some modules
16+
// may still use `module.exports` or if in TS `export = `
1517
return result.default || result;
1618
} catch (error) {
1719
if (error instanceof Error) {

0 commit comments

Comments
 (0)