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

Can not work `pretty: true` render

Open k725 opened this issue 1 year ago • 6 comments

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

k725 avatar Dec 04 '24 03:12 k725

The link for the reproduction seems to be down

gabrielmfern avatar Dec 04 '24 15:12 gabrielmfern

@gabrielmfern I accidentally made the repository private. I changed it to public so please check.

k725 avatar Dec 05 '24 01:12 k725

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)

SPodjasek avatar Dec 19 '24 18:12 SPodjasek

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].

SPodjasek avatar Dec 19 '24 19:12 SPodjasek

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>)

mririgoyen avatar Jan 13 '25 16:01 mririgoyen

Same issue here with Cannot read properties of undefined . Also reported here https://github.com/resend/react-email/pull/1777#issuecomment-2539465482

gewfy avatar Jan 14 '25 12:01 gewfy

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]

gabrielmfern avatar Jun 10 '25 15:06 gabrielmfern