Licence - ReferenceError: document is not defined

Posted by: ross.hulford on 23 February 2023, 5:56 am EST

  • Posted 23 February 2023, 5:56 am EST

    I am trying to run a basic example but get the error.

    ReferenceError: document is not defined

    Do I need a key?

    The is the turorial.

    https://www.grapecity.com/blogs/how-to-generate-excel-spreadsheets-in-nodejs

    These lines are commented out/

    //GC.Spread.Sheets.LicenseKey = “”;

    //SJSExcel.LicenseKey = “”;

  • Posted 24 February 2023, 5:57 am EST - Updated 24 February 2023, 6:47 am EST

    Hi,

    To ensure smooth operation of SpreadJS within a NodeJS environment, a valid license key is required. Additionally, you may come across the “document is not defined” error if a browser environment is not properly mocked. While SpreadJS is not officially supported in NodeJS, you can still use it in this environment by leveraging the “mock-browser” node package.

    var mockBrowser = require('mock-browser').mocks.MockBrowser;
    global.window = mockBrowser.createWindow();
    global.document = window.document;
    global.navigator = window.navigator;
    global.HTMLCollection = window.HTMLCollection;
    global.getComputedStyle = window.getComputedStyle;
    global.self = global.window
    

    In the event that you continue to experience issues, we kindly request that you share a working sample that reproduces the issue. This will enable us to investigate further and provide you with targeted assistance. Please refer to the code snippet provided below for further guidance.

    Thank you for your cooperation.

    Regards,

    Avinash

Need extra support?

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

Learn More

Forum Channels