This repository was archived by the owner on Jul 29, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change 11import React from "react" ;
2+ import fs from "fs" ;
23
34import { render } from "./renderer" ;
45import { isJsFile } from "../utils" ;
@@ -47,10 +48,24 @@ function importComponent(filepath: string): Promise<TemplateFunction | undefined
4748 try {
4849 // we should import component only in NodeJS
4950 if ( require === undefined ) resolve ( undefined ) ;
50- // remove from cache imported file
51- delete require . cache [ require . resolve ( filepath ) ] ;
5251
53- const component = require ( filepath ) ;
52+ let componentPath = filepath ;
53+
54+ // Check if the file exists
55+ if ( ! fs . existsSync ( componentPath ) ) {
56+ // If transpiled version doesn't exist, try the original version
57+ const originalPath = componentPath . replace ( '__transpiled' , 'template' ) ;
58+ if ( fs . existsSync ( originalPath ) ) {
59+ componentPath = originalPath ;
60+ } else {
61+ throw new Error ( `Neither transpiled nor original template file found: ${ filepath } ` ) ;
62+ }
63+ }
64+
65+ // Remove from cache and require the file
66+ delete require . cache [ require . resolve ( componentPath ) ] ;
67+ const component = require ( componentPath ) ;
68+
5469 if ( typeof component === "function" ) resolve ( component ) ;
5570 if ( typeof component . default === "function" ) resolve ( component . default ) ;
5671 resolve ( undefined ) ;
You can’t perform that action at this time.
0 commit comments