shellscape / jsx-email

Build emails with a delightful DX
https://jsx.email
MIT License
1.05k stars 35 forks source link

Cannot access 'exports' before initialization #235

Closed DenisLaboureyras closed 3 days ago

DenisLaboureyras commented 4 days ago

Expected Behavior

The render function is working in CommonJS

Actual Behavior

I use a monorepo with pnpm and turborepo, when I trigger programmaticaly an email with the render function, the API throw this error:

ReferenceError: Cannot access 'exports' before initialization at loadConfig (/node_modules/.pnpm/jsx-email@2.1.2_@jsx-email+app-preview@1.2.6_@types+node@22.8.5_react@18.3.1_rollup@4.24.0_sa_mdygf2jpttdrtguyc2kz5zafcm/node_modules/jsx-email/src/config.ts:215:56) at render (/node_modules/.pnpm/jsx-email@2.1.2_@jsx-email+app-preview@1.2.6_@types+node@22.8.5_react@18.3.1_rollup@4.24.0_sa_mdygf2jpttdrtguyc2kz5zafcm/node_modules/jsx-email/src/renderer/render.ts:28:32)

The offending code in cjs is the following:

if (globalThis[exports.globalConfigSymbol]) return globalThis[exports.globalConfigSymbol]; ... const exports = searchResult?.config ?? {};

There is a mix between the exports keyword and the exports variable, you should rename the exports variable to avoid this name collision.

Additional Information

shellscape commented 4 days ago

If you don't provide a reproduction, we cannot help you.

DenisLaboureyras commented 4 days ago

Here is the reproduction link: https://stackblitz.com/edit/jsx-email-repro-gkk1ey?file=package.json

In the terminal, "npm run dev" should triggered the error

shellscape commented 3 days ago

Thanks. Looking into it.

shellscape commented 3 days ago

I have a fix. Should be up within the hour.

DenisLaboureyras commented 3 days ago

Thanks a lot !