Spreadjs on Nodejs-Server (> V22.x) got error with setting navigator

Posted by: nguyenvu.work on 16 June 2025, 4:08 am EST

    • Post Options:
    • Link

    Posted 16 June 2025, 4:08 am EST - Updated 16 June 2025, 4:22 am EST

    • Hi! I am using Spreadjs on node-server (v22.16.0) following the document, there is a setting for navigator:
    const mockBrowser = require('mock-browser').mocks.MockBrowser;
    global.navigator = window.navigator;
    
    • After run “yarn start” I got an error: Cannot set property navigator of # which has only a getter,…
    • As I researched, with the new node versions, there is something call “the JavaScript engine (V8) enforces stricter property descriptors”. I tried to fix by some solution but nothing work.
    • Can I use Spreadjs on Node-server with the node versions that include “stricter property descriptors” ? Are there any solution for this issue?
  • Posted 16 June 2025, 5:06 am EST - Updated 16 June 2025, 5:15 am EST

    Hi,

    We are not able to reproduce the issue you mentioned on our end using NodeJS Version 22.16.0. Please refer to the attached sample that works as expected and sets various variables to the global object without throwing any errors (see below).

    Could you please share a stripped-down sample application to investigate the issue further? You can also modify and share the attached sample to replicate the issue.

    Gif:

    Sample: NodeVer.zip

    Regards,

  • Posted 16 June 2025, 6:30 am EST - Updated 16 June 2025, 7:20 am EST

    • Sorry for missing crucial information, in my project, I use webpack and typescripts to build the project then run
      node dist/index.js
      , I got an error: “Cannot set property navigator of # which has only a getter,…”
    • Is this the differences?
    • I logged the global.navigator (in NodeVer.zip), then I got an empty object “Navigator {}”. Is this will be worked correctly in the project?

      NodeServices.zip
    • yarn
    • yarn build
    • yarn start (get error)
  • Posted 16 June 2025, 8:01 am EST - Updated 16 June 2025, 8:06 am EST

    Hi,

    Thanks for sharing additional details.

    You’re correct that newer Node.js versions (especially v22+) have introduced stricter JavaScript engine rules that prevent direct assignment to certain global properties like navigator.

    To address this behavior, we recommend updating your code to use Object.defineProperty instead of directly assigning global.navigator. This approach safely bypasses the restriction and allows SpreadJS to function as expected in the simulated browser environment.

    Please refer to the updated code snippet:

    Object.defineProperty(global, 'navigator', {
      value: window.navigator,
      configurable: true,
    });

    This technique is safe and commonly used when simulating browser-like environments in Node.js, and we have confirmed it works correctly with mock-browser and SpreadJS under Node.js v22.16.0.

    You can also refer to the attached code sample that demonstrates the above solution (see below).

    GIF:

    Sample: NodeVer.zip

    Please let us know if you encounter any further issues or require additional guidance.

    Regards,

  • Posted 16 June 2025, 11:57 pm EST

    • Hi, Thank you for your supports, I resolved issue about navigator.
    • In my project there is a line code that setup CultureManager in the index file.
    GC.Spread.Common.CultureManager.culture('jp');
    
    • Above line cause got another error: TypeError: Argument to dispatchEvent must be an Event

      (Please refer to the attached code sample )
    • I am not sure, seem that error relevant to jsdom (you can check release note jsdom v24.1.2, fix issue addEvenlistener).

      NodeServices.zip
  • Posted 17 June 2025, 4:55 am EST - Updated 17 June 2025, 5:00 am EST

    Hi,

    We can replicate the behavior you mentioned on our end.

    The root cause of the issue is that certain DOM-dependent APIs within SpreadJS require a browser-like environment, especially for dispatching DOM events during culture setup. The mock-browser does not provide complete support for event handling and therefore fails when culture-related APIs such as CultureManager.culture(“jp”) are invoked.

    To resolve this, we recommend switching from mock-browser to jsdom. jsdom offers a more accurate simulation of the browser environment, including event dispatching support required by SpreadJS internally.

    Please refer to the updated code sample for your reference (see below).

    Attachments:

    GIF:

    Please feel free to reach out if you encounter any further issues or require additional assistance.

    Regards,

  • Posted 18 June 2025, 4:44 am EST

    • Thank you so much! My issue was resolved!
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels