Skip to content

Commit 8e4afce

Browse files
authored
fix(react-email): Support for users with NodeNext-style imports (#2227)
1 parent f68c9c1 commit 8e4afce

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

.changeset/deep-signs-push.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-email": patch
3+
---
4+
5+
fix hot reloading support for users with `NodeNext`-style imports

packages/react-email/src/cli/utils/preview/hot-reloading/create-dependency-graph.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,26 @@ export const createDependencyGraph = async (directory: string) => {
142142
}
143143
}
144144

145-
/*
146-
If the path to the dependency does not include a file extension, such that our check
147-
for it being a javascript module fails, then we can assume it has the same as the `filePath`
148-
*/
149-
if (!isJavascriptModule(pathToDependencyFromDirectory)) {
150-
const pathWithExtension =
151-
path.extname(pathToDependencyFromDirectory).length > 0
152-
? pathToDependencyFromDirectory
153-
: checkFileExtensionsUntilItExists(pathToDependencyFromDirectory);
154-
155-
if (pathWithExtension) {
156-
pathToDependencyFromDirectory = pathWithExtension;
157-
} else if (isDev) {
158-
// only warn about this on development as it is probably going to be irrelevant otherwise
159-
console.warn(
160-
`Could not determine the file extension for the file at ${pathToDependencyFromDirectory}`,
161-
);
145+
const extension = path.extname(pathToDependencyFromDirectory);
146+
const pathWithEnsuredExtension = (() => {
147+
if (
148+
extension.length > 0 &&
149+
existsSync(pathToDependencyFromDirectory)
150+
) {
151+
return pathToDependencyFromDirectory;
162152
}
153+
return checkFileExtensionsUntilItExists(
154+
pathToDependencyFromDirectory.replace(extension, ''),
155+
);
156+
})();
157+
158+
if (pathWithEnsuredExtension) {
159+
pathToDependencyFromDirectory = pathWithEnsuredExtension;
160+
} else if (isDev) {
161+
// only warn about this on development as it is probably going to be irrelevant otherwise
162+
console.warn(
163+
`Could not find file at ${pathToDependencyFromDirectory}`,
164+
);
163165
}
164166

165167
return pathToDependencyFromDirectory;

0 commit comments

Comments
 (0)