react-email
react-email copied to clipboard
Can not work `pretty: true` render
Describe the Bug
Specify pretty: true in render(), an exception will be thrown.
Which package is affected (leave empty if unsure)
@react-email/render
Link to the code that reproduces this issue
https://github.com/k725/reproduce-react-email-pretty-error
To Reproduce
git clone https://github.com/k725/reproduce-react-email-pretty-error
cd reproduce-react-email-pretty-error
npm i
npm run build-tsc
# work
node index-no-pretty.js
# throw error
node index-pretty.js
Expected Behavior
Return rendered html.
What's your node version? (if relevant)
v22.12.0
The link for the reproduction seems to be down
@gabrielmfern I accidentally made the repository private. I changed it to public so please check.
I've run into similar issue, but it seems to be related to prettier being very standards compliant. My exception shows:
SyntaxError: Unexpected closing tag "td". It may happen when the tag has already been closed
by another tag. For more info see
https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (2:231)
It was working properly with @react-email/components at version 0.0.19 and stopped working after upgrade to 0.0.31.
I've managed to narrow it down to version 0.0.29 in which the issue started to appear. This components version uses @react-email/[email protected] which depends on [email protected].
Can confirm that this is indeed an issue with the pretty flag. When using the pretty flag, a TypeError is dumped to the console:
TypeError: Cannot read properties of undefined (reading 'languages')
at /my-project/node_modules/prettier/standalone.js:28:694
at Array.flatMap (<anonymous>)
at st (/my-project/node_modules/prettier/standalone.js:28:681)
at vi (/my-project/node_modules/prettier/standalone.js:31:12039)
at sr (/my-project/node_modules/prettier/standalone.js:37:273)
at /my-project/node_modules/prettier/standalone.js:39:802
at gu (/my-project/node_modules/prettier/standalone.js:39:871)
at pretty (/my-project/node_modules/@react-email/render/dist/node/index.js:87:39)
at /my-project/node_modules/@react-email/render/dist/node/index.js:163:12
at Generator.next (<anonymous>)
Same issue here with Cannot read properties of undefined . Also reported here https://github.com/resend/react-email/pull/1777#issuecomment-2539465482
Tried it out on the reproduction, and it seems to have been fixed as of the latest versions. Particularly after @react-email/[email protected]/@react-email/[email protected]