Fix Excel Office.js context.sync JSON Serialization Errors
Question details
A developer encounters a JSON cyclic structure error when running an Excel Office.js add-in deployed on Firebase.

- Product
- Microsoft Excel (Office.js Add-in)
- Device & OS
- not provided
- Scenario
- Deploying an Excel add-in to Firebase and executing the insertWorksheetsFromBase64 operation.
- Observed behavior
- The add-in functions correctly on localhost but throws a context.sync JSON serialization error stating cyclic structures cannot be serialized after deployment.
Ensure your localhost development environment matches your Firebase production environment as closely as possible, and check if your build process is altering the structure of your JavaScript objects.
Remove Circular References from the Payload
Prevent JSON.stringify cyclic structure errors by ensuring only plain, serializable string data is passed to the insertWorksheetsFromBase64 API.
The context.sync operation requires all queued commands to be serialized into JSON before being sent to the Excel host application. If a complex object, such as a DOM element or an unparsed HTTP response object, is accidentally passed to the API instead of a primitive string, the serialization process will fail.
Locate the exact variable being passed into the insertWorksheetsFromBase64() method in your code.
Ensure that the variable is strictly a base64 encoded string. If you are retrieving the base64 data from an API or an object wrapper, extract only the string property and discard the rest of the object.
Before calling context.sync(), add a debug line like console.log(JSON.stringify(yourPayload)) to verify that the target data serializes successfully without throwing a cyclic error.
Once the circular references or complex object wrappers are removed, build your project and deploy the updated add-in files to Firebase.

Edit Spreadsheets with WPS Office
If you are dealing with persistent add-in errors or developer overhead in Microsoft Excel, consider WPS Office as a lightweight, highly compatible alternative for managing your daily spreadsheet tasks and JavaScript macro automations seamlessly.
- 1. Download WPS Office: Visit the official WPS Office website to download and install the free suite on your device.
- 2. Open your workbook: Launch WPS Spreadsheet and open your existing .xlsx files directly without any formatting loss.
- 3. Explore automation: Navigate to the Tools tab and select JS Macro to write JavaScript automations safely and efficiently.

Frequently Asked Questions
Why does my Office.js add-in work on localhost but fail on Firebase?
This is typically caused by differences between your development and production environments. Build tools (like Webpack or Vite) used prior to deploying to Firebase might minify code or alter objects, inadvertently exposing circular references that JSON.stringify cannot handle during context.sync.
How do I find circular references in my JavaScript objects?
You can identify circular references by using a custom replacer function in JSON.stringify() to catch cyclic links, or by inspecting the object in your browser's developer console for nested references that loop back to the parent object.
What data format does insertWorksheetsFromBase64 require?
The API strictly requires a valid base64-encoded string representing the workbook. Passing the entire File object, a Blob, or a complex HTTP response wrapper instead of the raw string will trigger serialization errors.




