App router email preview not importing email properly
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
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
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 devcommand. - Track the generated app with Git. Don't forget to add
.next&node_modulesto.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 what error are you referring to?
I have followed the steps to reproduce and the setup works fine.
I followed the same steps and I was able to reproduce the error.
I marked the parts which causes this error + additional errors.
If you check the commits from the PR #869 you can see that the PR changes the parts I marked.
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 devcommand.- Track the generated app with Git. Don't forget to add
.next&node_modulesto.gitignoreThis 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
This should not happen with the new version for the CLI [email protected] as it doesn't use this import hack anymore.