react-email icon indicating copy to clipboard operation
react-email copied to clipboard

App router email preview not importing email properly

Open Coderman562 opened this issue 3 years ago • 6 comments

Describe the Bug

import issue when importing email

./src/app/preview/[slug]/page.tsx:26:23 Module not found: Can't resolve '../../../../emails' 24 | }); 25 |

26 | const Email = (await import(../../../../emails/${params.slug})).default; | ^ 27 | const markup = render(, { pretty: true }); 28 | const plainText = render(, { plainText: true }); 29 | const basePath = pathJoin(process.cwd(), CONTENT_DIR);

https://nextjs.org/docs/messages/module-not-found

Which package is affected (leave empty if unsure)

No response

Link to the code that reproduces this issue

https://github.com/Coderman562/react-email-starter

To Reproduce

npx create-email@latest

cd react-email-starter

npm install

npm run dev

Expected Behavior

should import the react email code properly and display on page, instead gives error

What's your node version? (if relevant)

v18.16.1

Coderman562 avatar Aug 05 '23 16:08 Coderman562

Hey @Coderman562,

I just try to reproduce this and the setup works fine. Here is a video of me going through the setup process from scratch with the steps to reproduce (Maybe try using Yarn)

Link: https://youtu.be/Xg7zUt9ToP0

lordelogos avatar Aug 12 '23 01:08 lordelogos

The PR #869 fixes this issue. I also have a similar fix for this issue but i liked #869 better, so won't create a PR.

I have a suggestion, though.

  • Install [email protected] using automated setup.
  • Apply the PR into auto generated NextJS app that has been created when you first run email dev command.
  • Track the generated app with Git. Don't forget to add .next & node_modules to .gitignore

This way, you can atleast use the project without the wait.

NOTE: This version ([email protected]) has another problem on its email dev script. Main process rejects to exit on SIGINT signal since it can not gracefully shutdown. It can't kill the sub process and rejects to exit main process.

alper-guven avatar Aug 12 '23 15:08 alper-guven

@alper-guven what error are you referring to?

I have followed the steps to reproduce and the setup works fine.

lordelogos avatar Aug 12 '23 16:08 lordelogos

I followed the same steps and I was able to reproduce the error.

react-email--error

I marked the parts which causes this error + additional errors.

react-email--fix

If you check the commits from the PR #869 you can see that the PR changes the parts I marked.

alper-guven avatar Aug 12 '23 18:08 alper-guven

The PR #869 fixes this issue. I also have a similar fix for this issue but i liked #869 better, so won't create a PR.

I have a suggestion, though.

  • Install [email protected] using automated setup.
  • Apply the PR into auto generated NextJS app that has been created when you first run email dev command.
  • Track the generated app with Git. Don't forget to add .next & node_modules to .gitignore

This way, you can atleast use the project without the wait.

Followed the steps, though the import error persists, I seem to have to move the emails folder into the auto-generated .react-email folder manually for it to work. Is this by design, or a bug?

(I'm using npm, when using yarn the next server didn't start at all)

Edit: to use yarn, I had to disable PnP: run yarn config set nodeLinker node-modules the import error persists

nojuskybartas avatar Aug 23 '23 07:08 nojuskybartas

This should not happen with the new version for the CLI [email protected] as it doesn't use this import hack anymore.

gabrielmfern avatar Jan 23 '24 13:01 gabrielmfern