Cannot Test an Extension on a Local Server

In some 2018.2 implementations of SuiteCommerce Advanced, developers might experience the following console error when testing an extension on a local server: TypeError: SC.addExtensionModule is not a function. The patch instructions described below correct this error.

To implement this patch, you must create two custom modules to override different instances of index-local.ssp. These files are located in the Internals directory of the following modules (where X.Y.Z represents the version of the module in your implementation):

You can download the code samples described in this procedure here: RunExtensionsOnALocalServer.zip.

Note:

In general, NetSuite best practice is to extend JavaScript using the JavaScript prototype object. This improves the chances that your customizations continue to work when migrating to a newer version of SuiteCommerce Advanced. However, this patch requires you to modify a file in a way that you cannot extend, and therefore requires you to use a custom module to override the existing module file. For more information, see Develop Your SCA Customization.

Step 1: Create the Override Files

  1. Create an extensions directory to store each of your new custom modules. Depending on your implementation, this directory might already exist.

    Create two custom modules and give them names similar to the modules being customized. For example, create the following files:

    Modules/extensions/CheckoutApplicationExtension@1.0.0

    Modules/extensions/MyAccountApplicationExtension@1.0.0

  2. In each module, create a subdirectory called Internal.

    For example:

    • Modules/extensions/CheckoutApplicationExtension@1.0.0/Internal

    • Modules/extensions/MyAccountApplicationExtension@1.0.0/Internal

  3. Copy the following source files and paste into the correct location:

    Copy This File:

    Place a Copy Here:

    Modules/suitecommerce/CheckoutApplication@X.Y.Z/Internal/index-local.ssp

    Modules/extensions/CheckoutApplicationExtension@1.0.0/Internal

    Modules/suitecommerce/MyAccountApplication@X.Y.Z/Internal/index-local.ssp

    Modules/extensions/MyAccountApplicationExtension@1.0.0/Internal

    In this example, X.Y.Z represents the version of the module in your implementation of SuiteCommerce Advanced.

  4. For each new copy of index-local.ssp, add the following lines after the loadscript() function:

                    SC.extensionModules = [];
    SC.addExtensionModule = function addExtensionModule(appModuleName) {
       SC.extensionModules.push(appModuleName);
    }; 
    
                  

    Each file should look similar to the following example:

                    //...
    function loadScript (url)
    {
       'use strict';
       var reference_tag = document.getElementsByTagName("script")[0];
       var new_script_tag = document.createElement("script");
       new_script_tag.src = url;
       new_script_tag.type = "text/javascript";
       new_script_tag.async = false;
       reference_tag.parentNode.insertBefore(new_script_tag, reference_tag);
    }
    
    SC.extensionModules = [];
    SC.addExtensionModule = function addExtensionModule(appModuleName) {
       SC.extensionModules.push(appModuleName);
    };
    //... 
    
                  
  5. Save each file.

Step 2: Prepare the Developer Tools For Your Customization

  1. Create a file called ns.package.json in each of your custom modules.

    For example:

    • Modules/extensions/CheckoutApplicationExtension@1.0.0/ns.package.json

    • Modules/extensions/MyAccountApplicationExtension@1.0.0/ns.package.json

  2. Paste the following code in each ns.package.json file, as applicable:

    CheckoutApplication
                    {
       "gulp": {
          "ssp-files": [
                "Internal/*.ssp"
          ]
       },
       "overrides": {
          "suitecommerce/CheckoutApplication@X.Y.Z/Internal/index-local.ssp" : "Internal/index-local.ssp"
       }
    } 
    
                  
    MyAccountApplication
                    {
       "gulp": {
          "ssp-files": [
                "Internal/*.ssp"
          ]
       },
       "overrides": {
          "suitecommerce/MyAccountApplication@X.Y.Z/Internal/index-local.ssp" : "Internal/index-local.ssp"
       }
    } 
    
                  
    Important:

    You must replace the string X.Y.Z with the version of the module in your implementation of SuiteCommerce Advanced.

  3. Open the distro.json file. This file is located in your root directory.

  4. Add both custom modules to the modules object.

    Your code should look similar to the following example:

                    {
        "name": "SuiteCommerce Advanced 2018.2.0",
        "version": "2.0",
        "isSCA": true,
        "buildToolsVersion": "1.3.1",
        "folders": {
            "modules": "Modules",
            "suitecommerceModules": "Modules/suitecommerce",
            "extensionsModules": "Modules/extensions",
            "thirdPartyModules": "Modules/third_parties",
            "distribution": "LocalDistribution",
            "deploy": "DeployDistribution"
        },
             "modules": {
                "extensions/CheckoutApplicationExtension": "1.0.0",
                "extensions/MyAccountApplicationExtension": "1.0.0",
                "suitecommerce/Account": "sc-2018.2.0",
                ... 
    
                  

    This step ensures that the Gulp tasks include your module when you deploy your code to NetSuite. In this example, the custom modules are added at the beginning of the list of modules. However, you can add the modules anywhere in the modules object. The order of precedence in this list does not matter.

  5. Save the distro.json file.

Step 3: Test and Deploy Your Customization

  1. Deploy your changes to your NetSuite account (see Deploy SCA Customizations to NetSuite). If you are currently running SCA on a local server, your changes should appear on your local site immediately.

    Note:

    Because this patch modifies an SSP library file, changes are not visible in your local environment until you first deploy the customizations to NetSuite.

  2. Confirm your results.

    Upon successful deployment, you should be able to test your extensions on a local server.

Related Topics

SCA Patches

General Notices