Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Converting circular structure to JSON when sending emails #3277

Closed
michaelbromley opened this issue Dec 16, 2024 · 2 comments
Closed
Labels
type: bug 🐛 Something isn't working

Comments

@michaelbromley
Copy link
Member

Describe the bug
When attempting to send certain emails in v3.1.0, a circular JSON error is thrown by the EmailPlugin on the server, preventing the email from getting sent.

To Reproduce
Steps to reproduce the behavior:

  1. With a standard installation
  2. Go through a regular checkout flow and complete the order
  3. When the order confirmation email is triggered, you will see the following error:
[server] error 16/12/24, 12:01 - [EmailPlugin] Converting circular structure to JSON
[server] TypeError: Converting circular structure to JSON
[server]     --> starting at object with constructor 'Object'
[server]     |     property 'sessionCacheStrategy' -> object with constructor 'DefaultSessionCacheStrategy'
[server]     |     property 'cacheService' -> object with constructor 'CacheService'
[server]     |     ...
[server]     |     property 'activeConfig' -> object with constructor 'Object'
[server]     --- property 'authOptions' closes the circle
[server]     at JSON.stringify (<anonymous>)
[server]     at Job.asJSON (C:\Development\vendure\vendure\node_modules\bullmq\src\classes\job.ts:446:18)
[server]     at Job.addJob (C:\Development\vendure\vendure\node_modules\bullmq\src\classes\job.ts:1175:26)
[server]     at Function.create (C:\Development\vendure\vendure\node_modules\bullmq\src\classes\job.ts:227:24)
[server]     at processTicksAndRejections (node:internal/process/task_queues:95:5)
[server]     at async Queue.add (C:\Development\vendure\vendure\node_modules\bullmq\src\classes\queue.ts:209:19)
[server]     at async BullMQJobQueueStrategy.add (C:\Development\vendure\vendure\packages\job-queue-plugin\src\bullmq\bullmq-job-queue-strategy.ts:162:25)
[server]     at async JobQueue.add (C:\Development\vendure\vendure\packages\core\src\job-queue\job-queue.ts:102:30)
[server]     at async EmailPlugin.handleEvent (C:\Development\vendure\vendure\packages\email-plugin\src\plugin.ts:426:17)

Expected behavior
No error and the email gets sent

Environment (please complete the following information):

  • @vendure/core version: 3.1.0
  • Nodejs version: any
  • Database (mysql/postgres etc): any

Additional context
Discussion on Discord: https://discord.com/channels/1100672177260478564/1316447090142085222/1316447090142085222

@michaelbromley michaelbromley added the type: bug 🐛 Something isn't working label Dec 16, 2024
@michaelbromley michaelbromley moved this to ♻️ In progress in Vendure OS Roadmap Dec 16, 2024
@Clemens05
Copy link

I had the same error. A quick fix is to removed the allCheckers property from event.data.shippingLines in setTemplateVars like this:

const shippingLines = event.data.shippingLines.map(
  (shippingLine) => ({
    ...shippingLine,
    shippingMethod: {
      ...shippingLine.shippingMethod,
      allCheckers: undefined,
    },
  })
);

return {
  order: { ...event.order, shippingLines: shippingLines },
  shippingLines: shippingLines,
  // ...
};

Maybe that helps to identify the root cause of the error.

@michaelbromley
Copy link
Member Author

Yes - good detective work. The root cause is indeed the shipping method serialization. I'm adding a suite of tests on entity serialization that will address this and catch any similar regressions in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Something isn't working
Projects
Status: ♻️ In progress
Development

No branches or pull requests

2 participants