Requirejs and stimul

Stimulsoft Reports.JS discussion
Post Reply
alireza_s_84
Posts: 18
Joined: Fri Jan 27, 2017 4:43 am

Requirejs and stimul

Post by alireza_s_84 »

Hi
If we load Requirejs before Stimul then get error. are there any way to use stimul in a requirejs module?
The error is:

Code: Select all

Uncaught ReferenceError: moment_mod is not defined
Barnaby
Posts: 27
Joined: Tue Dec 20, 2016 1:57 am

Re: Requirejs and stimul

Post by Barnaby »

Hi, I ran into the same problem, and found a way to get it working.

You need to add and load momentjs before you load stimulsoft.reports.

I moved it all into requirejs, then made my requirejs config load it in this order: momentjs -> reports -> viewer -> designer
For example

Code: Select all

requirejs.config({
   paths: {
      "momentjs": '/Stimulsoft/scripts/moment',
      "StimulsoftReports": '/Stimulsoft/scripts/stimulsoft.reports',
      "StimulsoftViewer": '/Stimulsoft/scripts/stimulsoft.viewer',
      "StimulsoftDesigner": '/Stimulsoft/scripts/stimulsoft.designer'
   },
   shim: {
      'StimulsoftDesigner': ['StimulsoftViewer'],
      'StimulsoftViewer': ['StimulsoftReports'],
      'StimulsoftReports': ['momentjs']
   }
});
Then you would just need to define StimulsoftDesigner or StimulsoftViewer.

Code: Select all

require(['StimulsoftDesigner'], function()
{
   // use Stimulsoft here
});
alireza_s_84
Posts: 18
Joined: Fri Jan 27, 2017 4:43 am

Re: Requirejs and stimul

Post by alireza_s_84 »

Barnaby wrote: Wed Feb 06, 2019 3:14 am Hi, I ran into the same problem, and found a way to get it working.

You need to add and load momentjs before you load stimulsoft.reports.

I moved it all into requirejs, then made my requirejs config load it in this order: momentjs -> reports -> viewer -> designer
For example

Code: Select all

requirejs.config({
   paths: {
      "momentjs": '/Stimulsoft/scripts/moment',
      "StimulsoftReports": '/Stimulsoft/scripts/stimulsoft.reports',
      "StimulsoftViewer": '/Stimulsoft/scripts/stimulsoft.viewer',
      "StimulsoftDesigner": '/Stimulsoft/scripts/stimulsoft.designer'
   },
   shim: {
      'StimulsoftDesigner': ['StimulsoftViewer'],
      'StimulsoftViewer': ['StimulsoftReports'],
      'StimulsoftReports': ['momentjs']
   }
});
Then you would just need to define StimulsoftDesigner or StimulsoftViewer.

Code: Select all

require(['StimulsoftDesigner'], function()
{
   // use Stimulsoft here
});
Thanks, but not work for me:

Code: Select all

require.config({
    baseUrl: "@Url.Content("~/scripts/")",
    urlArgs: function (id, url) {
        var d = new Date().getTime();
        return (url.indexOf('?') === -1 ? '?' : '&') + "vr=" + d;
    },
    paths: {
        momentjs: "stimul/moment",
        StimulsoftReports: "stimul/stimulsoft.reports",
        StimulsoftViewer: "stimul/stimulsoft.viewer"
    },
    shim: {
        StimulsoftViewer: ["StimulsoftReports"],
        StimulsoftReports: ["momentjs"],
        bootstrap: ["jquery"]
    },
    waitSeconds: 60
});
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: Requirejs and stimul

Post by Lech Kulikowski »

Hello,

Please send us a sample project which reproduces the issue for analysis on support@stimulsoft.com

Thank you.
gilgil
Posts: 2
Joined: Sat Feb 16, 2019 2:18 pm

Re: Requirejs and stimul

Post by gilgil »

try this
after load momentjs add this code (momentAdaptor)

Code: Select all

window.moment_mod = moment;
require Config

Code: Select all

            'momentAdapter': {
                deps: ['momentjs']
            },
            'StimulsoftReports': {
                deps: ['momentAdapter']
            },
            'StimulsoftViewer': {
                deps: ['StimulsoftReports']
            },
            'StimulsoftDesigner': {
                deps: ['StimulsoftViewer']
            },
Barnaby
Posts: 27
Joined: Tue Dec 20, 2016 1:57 am

Re: Requirejs and stimul

Post by Barnaby »

You need more than momentjs for everything to work, things such as jszip, and xxhash.
So now rather than trying to find out what is required and load them in manually, I now take a more hacky approach, which is to make it think there is no amd, so it loads the normal javascript version with all of it built in.

So still having Report, Designer and Viewer in the config, I do this

Code: Select all

// require my normal stuff
require(['Example'], function(Example)
{
   // Temporarly remove the define.amd
   var _amd = define.amd;
   delete define.amd;

   // Load the designer
   require(['StimulsoftDesigner'], function()
   {
      // re-add the amd
      define.amd = _amd;

      // run designer code
   });
});
StimulsoftDesigner is required in its own bit, so that other modules don't try load without the amd set.
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: Requirejs and stimul

Post by Lech Kulikowski »

Hello,

Thank you for the information.
Post Reply