jsreport/jsreport-dotnet

Using 3rd party extensions

HEBOS opened this issue · 9 comments

HEBOS commented

Hi,

Is there any way to include any 3rd party library, such as formatJs.
I'm designing reports using local JsReport studio using feature ".AsWebServer()".

Thanks

hi! have you tried to follow these instructions?

HEBOS commented

Hi,
Thanks for the suggestions.
I'm struggling now several days.
I'd really appreciate your help.

I used suggested instruction, but "require("handlebars-intl") simply does not work.

Here is what I did.

In "jsonreport.config.json" I've put:

{
"tasks": {
"allowedModules": [ "fs", "handlebars", "handlebars-intl", "handlebars-helpers" ]
},
"scripts": {
"allowedModules": [ "fs", "handlebars", "handlebars-intl", "handlebars-helpers" ]
}
}

In "global helpers.js" I've put:

var handlebars = require('handlebars');

var HandlebarsIntl = require('handlebars-intl');
HandlebarsIntl.registerWith(handlebars);

var handlebars = require('handlebars');

var helpers = require('handlebars-helpers')({
handlebars: handlebars
});

Result:
Error: Unable to find module handlebars-intl
Searched paths:
handlebars-intl
u:\MongoPlus\MongoPlus.Web\Reports\handlebars-intl
u:\MongoPlus\MongoPlus.Web\Reports\handlebars-intl
u:\MongoPlus\MongoPlus.Web\Reports\handlebars-intl
at doRequire (jsreportRuntime.js:93:13)
at _require (jsreportRuntime.js:109:14)
at evalmachine.:12:22
at ContextifyScript.Script.runInNewContext (vm.js:18:15)
at Object.exports.runInNewContext (vm.js:49:17)
at module.exports (jsreportRuntime.js:192:10)
at ScriptsManager.execute (jsreportRuntime.js:263763:34)
at tryCatcher (jsreportRuntime.js:47291:23)
at ret (eval at (jsreportRuntime.js:45949:12), :13:39)
at invokeRender (jsreportRuntime.js:138903:88)
at jsreportRuntime.js:138965:12
at tryCatcher (jsreportRuntime.js:47291:23)
at Promise._settlePromiseFromHandler (jsreportRuntime.js:45313:31)
at Promise._settlePromise (jsreportRuntime.js:45370:18)
at Promise._settlePromise0 (jsreportRuntime.js:45415:10)
at Promise._settlePromises (jsreportRuntime.js:45494:18)
at Promise._fulfill (jsreportRuntime.js:45439:18)
at Promise._resolveCallback (jsreportRuntime.js:45233:57)
at Promise._settlePromiseFromHandler (jsreportRuntime.js:45325:17)
at Promise._settlePromise (jsreportRuntime.js:45370:18)
at Promise._settlePromise0 (jsreportRuntime.js:45415:10)
at Promise._settlePromises (jsreportRuntime.js:45494:18)
at Promise._fulfill (jsreportRuntime.js:45439:18)
at Promise._resolveCallback (jsreportRuntime.js:45233:57)
at Promise._settlePromiseFromHandler (jsreportRuntime.js:45325:17)
at Promise._settlePromise (jsreportRuntime.js:45370:18)
at Promise._settlePromise0 (jsreportRuntime.js:45415:10)
at Promise._settlePromises (jsreportRuntime.js:45494:18)
at Promise._fulfill (jsreportRuntime.js:45439:18)
at PromiseArray._resolve (jsreportRuntime.js:45704:19)
at PromiseArray._promiseFulfilled (jsreportRuntime.js:45722:14)
at Promise._settlePromise (jsreportRuntime.js:45375:26)
at Promise._settlePromise0 (jsreportRuntime.js:45415:10)
at Promise._settlePromises (jsreportRuntime.js:45494:18)
at Async._drainQueue (jsreportRuntime.js:42220:16)
at Async._drainQueues (jsreportRuntime.js:42230:10)
at Immediate.Async.drainQueues [as _onImmediate] (jsreportRuntime.js:42104:14)
at processImmediate [as _immediateCallback] (timers.js:396:17)

And, I've also installed into jsreport folder needed libraries using:
npm install handlebars
npm install handlebars-helper
npm install handlebars-intl

Please help!

Thanks

This should work. Can you make sure you have in the external modules got properly installed to jsreport/node_modules/handlebars-intl ?
It would help if you create a minimal repository (without your unrelated code) we can try to analyse.

HEBOS commented

Hi @pofider ,

I've attached a sample project. Note that I have two project. One is used for design time, and one for run time. Report folder is saved in run-time project (ReportServer), and design-time project (ReportDesigner) is used by developers only, otherwise they are similar.

Try to run this template:
http://localhost:55555/studio/templates/BJYoCEqnf

Code that does not execute is in "global helpers.js", e.g. http://localhost:55555/studio/assets/SkMw3X69l

SampleProject.zip

Thank you

Thank you.
I can replicate your issue, I will try to investigate what could be the problem in the next days.

Hm. It seems the handlebars-intl requires Intl but our compiled node.js version doesn't have it. The real error is unfortunately hidden and you can get it if you try/catch handlebars-intl/index and write the error to file...

I've submitted task here to investigate why our compilation of nodejs excludes Int. However this will take some time.

I would recommend to find an alternative to the handlebars-intl that doesn't require browser support for Intl and does the work manually.

I'm having the same problem: I cannot load momentjs for example.

I have the following jsreport.config.json:

{  
   "discover":true,
   "allowLocalFilesAccess":true,
   "templatingEngines":{  
      "allowedModules":"*"
   },
   "store":{  
      "provider":"fs"
   },
   "extensions":{  
      "comment":"helpers and scripts are different...",
      "tasks":{  
         "allowedModules":"*"
      },
      "scripts":{  
         "allowedModules":"*"
      },
      "assets":{  
         "allowedFiles":"static/**/*.*",
         "searchOnDiskIfNotFoundInStore":true,
         "rootUrlForLinks":"https://some.website.net",
         "publicAccessEnabled":false
      }
   },
   "scripts":{  
      "allowedModules":"*"
   }
}

and I get the following error:

Unhandled Exception: jsreport.Client.JsReportException: Unable to render template.  Error while executing user script. Unable to find module node_modules/moment/moment.js
Searched paths:
node_modules/moment/moment.js
C:\Projects\ConsoleApp3\reports\node_modules\moment\moment.js
C:\Projects\ConsoleApp3\reports\node_modules\moment\moment.js
C:\Projects\ConsoleApp3\reports\node_modules\moment\moment.js
.

The file is located here: C:\Projects\ConsoleApp3\reports\node_modules\moment\moment.js

I am running into this as well. Is there any update on this issue? This ticket has been open for 7 months and leaves helpers almost entirely unusable on dotnet platforms.

I apologize for the late response here.
The custom helpers from npm should work.
I have tested it with the latest jsreport.Binary.
It is also documented now - https://jsreport.net/learn/dotnet-local#custom-npm-helpers

The handlebars-intl unfortunately won't work because its dependency on some native features that are not build in, so you need to use a different package. It is also documented and we have extra issue for it here.

Closing. The 3rd party modules should work. Feel free to comment or create new issue if you have still problems on the latest version.