File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,18 @@ import * as _ from "lodash";
2727let triggers : EmulatedTriggerMap | undefined ;
2828let developerPkgJSON : PackageJSON | undefined ;
2929
30+ /**
31+ * Dynamically load import function to prevent TypeScript from
32+ * transpiling into a require.
33+ *
34+ * See https://github.com/microsoft/TypeScript/issues/43329.
35+ */
36+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
37+ const dynamicImport = new Function (
38+ "modulePath" ,
39+ "console.log(modulePath); return import(modulePath)"
40+ ) ;
41+
3042function isFeatureEnabled (
3143 frb : FunctionsRuntimeBundle ,
3244 feature : keyof FunctionsRuntimeFeatures
@@ -1065,8 +1077,13 @@ async function initializeRuntime(
10651077 try {
10661078 triggerModule = require ( frb . cwd ) ;
10671079 } catch ( err ) {
1068- await moduleResolutionDetective ( frb , err ) ;
1069- return ;
1080+ if ( err . code === "ERR_REQUIRE_ESM" ) {
1081+ // tslint:disable:no-unsafe-assignment
1082+ triggerModule = await dynamicImport ( require . resolve ( frb . cwd ) ) ;
1083+ } else {
1084+ await moduleResolutionDetective ( frb , err ) ;
1085+ return ;
1086+ }
10701087 }
10711088 }
10721089 if ( extensionTriggers ) {
You can’t perform that action at this time.
0 commit comments