sri harsha
sri harsha

Reputation: 47

require js is not supporting optional chaining at the bundling process (grunt bundler)

Running "requirejs:desktop" (requirejs) task
    Error: Parse error using esprima for file:
    C:/projects/GitProjects/vendorgames-sonarqube/ndcasinocommon/base_common/fcga
mes/vendorgames/utilities/utils.js
    Error: Line 17: Unexpected token .
    In module tree:
       desktop/init
           controller
               lobbyService
Warning: RequireJS failed. Use --force to continue.

Aborted due to warnings.

This error showing in CMD, on using JavaScript optional chaining in one of the files of bundler, require js is breaking the bundling process with grunt build command

"use strict";

module.exports = function(grunt) {

  var buildVersion = grunt.option('buildVersion') || '1.0';
  var currentVersion = grunt.option('currentVersion') || '1.0';

  grunt.initConfig({
    pkg: grunt.file.readJSON("package.json"),
    buildVersion: buildVersion,
    currentVersion: currentVersion,
    requirejs: {
      desktop: {
        options: {
          uglify2: {
            mangle: false
          },
          baseUrl: "./",
          mainConfigFile: "desktop/init.js",
          name: "desktop/init",
          out: "desktop/___FilesToBeCached___desktop.min.js",
          optimize: "none"
        }
      }
    },
    replace: {
      desktopReplace: {
        src: ["./Controller.html"],
        dest: "./",
        replacements: [{
          from: "desktop-min-<%=currentVersion%>",
          to: "desktop-min-<%=buildVersion%>"
        }]
      }
    },
    uglify: {
      desktop_build: {
        files: {
          "desktop/build.js": ["desktop/*.js", "desktop/**/*.js", "utilities/*.js"]
        }
      }
    }
  });

  grunt.loadNpmTasks("grunt-contrib-uglify");
  grunt.loadNpmTasks("grunt-contrib-requirejs");
  grunt.loadNpmTasks("grunt-text-replace");
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.file.setBase("../");
  grunt.registerTask("desktop", ["requirejs:desktop"]);
  grunt.registerTask("desktopReplace", ["replace:desktopReplace"]);
  grunt.registerTask("build", ["desktop", "desktopReplace"]);
};

this is the require js for the desktop code where bundling is happening

require.config({
    baseUrl: "./",
    paths: {
        utils: "utilities/utils",
    },
    shim: {
        jqueryUI: {
            deps: ['jquery']
        },
        jqueryTouch: {
            deps: ['jqueryUI']
        }
    }
});

In this file I am using optional chaining, here is that function

function getCookie(cname) {
    var name = cname + "=";
    var ca = document?.cookie.split(";");
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i].trim();
        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
    }
    return "";
}

I am using grunt bundler

If the file involved in the minified file, then facing this issue.

I want to make the build successfully bundling all the files with using es6 optional chaining features

I am using grunt bundler and require js to import and export files

Upvotes: 0

Views: 50

Answers (0)

Related Questions