react-email: `email dev` command always fails on Windows

Describe the Bug

I am using the latest version of React Email (2.0.0) and Next.js (13.5.4)

When I run “email dev” I get the following error:

    Running preview at:          http://localhost:3000

  ⠙ Getting react-email preview server ready...
Error: > Couldn't find any `pages` or `app` directory. Please create one under the project root

But I clearly do have an app directory… what’s going on? Also don’t really want to upgrade to Next 14 atm, because it’ll break some things.

Which package is affected (leave empty if unsure)

No response

Link to the code that reproduces this issue

https://github.com/lazlothemonkey/reactemail_test

To Reproduce

Just run “npm run email”

Expected Behavior

I expect to run the email preview server

What’s your node version? (if relevant)

No response

About this issue

  • Original URL
  • State: closed
  • Created 5 months ago
  • Reactions: 9
  • Comments: 31 (1 by maintainers)

Most upvoted comments

This has been fixed under react-email@2.1.0-canary.1, stable release soon!

There’s already a PR open for this issue, #1216, and here’s a patch as a quick workaround for now:

diff --git a/cli/index.js b/cli/index.js
index 15c8732e1bcf274d9d99ea8de55ed0e959fb5d16..69ef51c7eb11a02b0e2e5c95e0c95c92d5175735 100644
--- a/cli/index.js
+++ b/cli/index.js
@@ -508,7 +508,7 @@ var safeAsyncServerListen = function(server, port) {
         });
     });
 };
-var isRunningBuilt = __filename.endsWith("cli/index.js");
+var isRunningBuilt = __filename.endsWith(import_node_path3.default.join("cli", "index.js"));
 var cliPacakgeLocation = isRunningBuilt ? import_node_path3.default.resolve(__dirname, "..") : import_node_path3.default.resolve(__dirname, "../../../..");
 var startDevServer = function() {
     var _ref = _async_to_generator(function(emailsDirRelativePath, staticBaseDirRelativePath, port) {
diff --git a/src/utils/emails-directory-absolute-path.ts b/src/utils/emails-directory-absolute-path.ts
index 256fd506049dbd7d83c188d3785c535633482ee5..ccbcb541710a16ad84ba4fcf6312500db81097b2 100644
--- a/src/utils/emails-directory-absolute-path.ts
+++ b/src/utils/emails-directory-absolute-path.ts
@@ -14,15 +14,15 @@ export const pathSeparator = process.env.NEXT_PUBLIC_OS_PATH_SEPARATOR! as
 const normalizePath = (path: string) => {
   let newPath = path;
 
-  while (newPath.startsWith('./')) {
+  while (newPath.startsWith(`.${pathSeparator}`)) {
     newPath = newPath.slice(2);
   }
 
-  while (newPath.startsWith('/')) {
+  while (newPath.startsWith(pathSeparator)) {
     newPath = newPath.slice(1);
   }
 
-  while (newPath.endsWith('/')) {
+  while (newPath.endsWith(pathSeparator)) {
     newPath = newPath.slice(0, -1);
   }

@bennyburrito So sorry for the late reply here, but seems like the latest canary release has this fixed.

See issue #1354 and release notes https://github.com/resend/react-email/releases/tag/react-email%402.1.1-canary.1.

this fixed it for me!

nvm node v18.17.1

Yes this has fixed. Many thanks 😃

email dev -p 3030

   React Email 2.0.0
   Running preview at:          http://localhost:3030

 ⠙ Getting react-email preview server ready...
Error: > Couldn't find any `pages` or `app` directory. Please create one under the project root
    at findPagesDir (G:\projects\next13-ticketing-app\node_modules\react-email\node_modules\next\dist\lib\find-pages-dir.js:42:15)
   at initialize (G:\projects\next13-ticketing-app\node_modules\react-email\node_modules\next\dist\server\lib\router-server.js:71:69)
   at async NextCustomServer.prepare (G:\projects\next13-ticketing-app\node_modules\react-email\node_modules\next\dist\server\next.js:240:28)

shutting down dev server

@kapilrc The above issue you mention is the one that the patch and the PR #1216 fixes.

About the other issue you saw with the 1.x.x is something that used to happen here and there, so if you try enough I think it might not be an error.

@kapilrc Seems like you’re using the 1.x.x version for the CLI. If you use react-email@2.0.0 you won’t have that issue you are mentioning anymore. That being said this issue (#1225) is for the 2.0.0 version, not the 1.x.x.

See https://resend.com/blog/react-email-2