Hi Admin,
Thanks for the insights.
It's working as expected.
Will explore more on it and let you know any issue we face in future.
Hi Admin,
Thanks for the insights.
It's working as expected.
Will explore more on it and let you know any issue we face in future.
Hi Admin,
Thanks for your reply.
I followed the same. templates with helpers, content, engine, recipe, chrome are fine. For my template i need to pass the set of data as Json , How can i send the data to that function .
below is the code implementation
const requestBody=event.renderRequest
const resp = await jsreport.render(requestBody);
in requestBody will contain below data
{
template: {
content: "Hey Buddy this is called from the backend you know",
engine: "handlebars",
recipe: "chrome-pdf",
chrome: {
format: "A4",
orientation: "portrait",
fittopage: true,
margin: {
top: "30px",
left: "20px",
right: "20px",
bottom: "10px",
},
},
helpers: "function myFunction (x){return x}",
}
datas:[{temp1:"temp1Data"},{temp2:"temp2Data"}]}
}
Because these datas needs to be bind with my template.
Kindly check above and guide me to close this .
Thanks.
I configured this in Lambda function and i got the Functional URL aswell.
I need to use this service by calling this form Node Project.
Consider i have my templates and data and rest of the parameters.
How can i call this In my nodeJs and being served by lambda.
Hi Team, Good day.
In this Post i want to clarify that Can i send the data like given below to the jsreport starter kit which is used for lambda based configurations REFERENCE LINK: https://jsreport.net/learn/aws-lambda-serverless
Sample JSON request:
{
"renderRequest": {
"template": {
"content":`
\n' +
'<html lang="en">\n' +
'\n' +
'<head>\n' +
' <meta charset="UTF-8">\n' +
' <meta name="viewport" content="width=device-width, initial-scale=1.0">\n' +
' <title>My Website</title>\n' +
'\n' +
'</head>\n' +
'\n' +
'<body>\n' +
'\n' + // Added an empty line before your content area
' <header>\n' +
' <h1>Welcome to My Website</h1>\n' +
' </header>\n' +
'\n' +
' <main>\n' +
' <h2>Example Table</h2>\n' +
' <table>\n' +
' <tr>\n' +
' <th>Name</th>\n' +
' <th>Age</th>\n' +
' <th>City</th>\n' +
' </tr>\n' +
' <tr>\n' +
' <td>John Doe</td>\n' +
' <td>30</td>\n' +
' <td>New York</td>\n' +
' </tr>\n' +
' <tr>\n' +
' <td>Jane Smith</td>\n' +
' <td>25</td>\n' +
' <td>London</td>\n' +
' </tr>\n' +
' </table>\n' +
' </main>\n' +
'\n' +
' <footer>\n' +
' <p>© 2024 My Website</p>\n' +
' </footer>\n' +
'\n' +
'</body>\n' +
'\n' +
'</html>\n'
`
`;
,
"engine": "handlebars",
"recipe": "chrome-pdf",
"chrome": {
"format": "A4",
"orientation": "portrait",
"fittopage": true,
"margin": {
"top": "30px",
"left": "20px",
"right": "20px",
"bottom": "10px"
}
},
"helpers": " function myFunction (x){return x}"
}
}
}
In lambda actual jsreport npm packages not working. So i tried this way to implement the actual jsreport functionality in lambda based.
I will send the Request like given above. Kindly confirm whether this is right approach or not. Kindly guide me to get this done.
Thanks in advance
Hi Admin, Greetings of the day.
I have found my lambda function and got the code and i debugged the place and finally i found the place where that actual error is occur.
Code given below for more clarity:
var require_resolve2 = __commonJS({
"node_modules/app-root-path/lib/resolve.js"(exports2, module2) {
"use strict";
var path2 = require("path");
var globalPaths = require("module").globalPaths;
var npmGlobalPrefix;
if ("win32" === process.platform) {
npmGlobalPrefix = path2.dirname(process.execPath);
} else {
npmGlobalPrefix = path2.dirname(path2.dirname(process.execPath));
}
var npmGlobalModuleDir = path2.resolve(npmGlobalPrefix, "lib", "node_modules");
var sep = path2.sep;
module2.exports = function resolve(dirname) {
if (process.env.APP_ROOT_PATH) {
return path2.resolve(process.env.APP_ROOT_PATH);
}
if ("undefined" !== typeof window && window.process && "renderer" === window.process.type) {
var electron = "electron";
var remote = require(electron).remote;
return remote.require("app-root-path").path;
}
var resolved = path2.resolve(dirname);
var alternateMethod = false;
var appRootPath = null;
globalPaths.forEach(function(globalPath) {
if (!alternateMethod && 0 === resolved.indexOf(globalPath)) {
alternateMethod = true;
}
});
var nodeModulesDir = sep + "node_modules";
if (!alternateMethod && -1 !== resolved.indexOf(nodeModulesDir)) {
var parts = resolved.split(nodeModulesDir);
if (parts.length) {
appRootPath = parts[0];
parts = null;
}
}
if (alternateMethod || null == appRootPath) {
appRootPath = path2.dirname(require.main.filename);
}
if (alternateMethod && -1 !== appRootPath.indexOf(npmGlobalModuleDir) && appRootPath.length - 4 === appRootPath.indexOf(sep + "bin")) {
appRootPath = appRootPath.slice(0, -4);
}
return appRootPath;
};
}
});
In above code i have highlighted the part where that error occour.
Why that path2.dirname(require.main.filename) la filename property is undefined.
Help to get the root cause for this. Im not sure is this directory permission on AWS lambda. If anything like directory changes kindly let me know i will update my User permissions acccordingly.
Waiting for your message .
Folks If you have any insights please feel free to share. Thanks in Advance
In the given Tutorials Those are all manually create function and Layer building. But In our app is Doing everything all by automatic . We have serverless.yaml file to configure those things.
My Doubt is Why we need to clone that Repo first , How do that code will impact with my my Node Application.
Help me to get clear picture on this please. Let me know if you need any additional information.
Hi Admin, Thanks for your response.
As you instructed i have added the rootDirectory: __dirname in my jsreport-core and details given below. Still same issue exist , After deployment on lambda My Node App crash and Not running . throws 500 Error for all API calling. I![alt text](image url) have attached my configurations and Kindly check that and let me know what i missed.
import * as _ from "lodash";
const jsreport = require("jsreport-core")({
rootDirectory: __dirname,
});
jsreport.use(require("jsreport-handlebars")());
jsreport.use(require("jsreport-chrome-pdf")());
jsreport.use(require("jsreport-html-to-xlsx")());
jsreport.use(
require("jsreport-assets")({
searchOnDiskIfNotFoundInStore: true,
allowedFiles: "/.",
})
);
jsreport.init();
Kindly help me on this. I have added the Jsreport dependency in my layers package.json file also.
{
"name": "testlambda",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"pg": "^8.10.0",
"pg-native": "^3.0.1",
"axios": "^1.3.4",
"jsreport-assets": "^1.7.0",
"jsreport-chrome-pdf": "^1.10.0",
"jsreport-core": "^2.10.1",
"jsreport-handlebars": "^2.1.0",
"jsreport-html-to-xlsx": "2.6.0",
"jsreport-phantom-pdf": "^2.6.1",
"should": "^13.2.3",
"emitter": "^0.0.5"
},
"devDependencies": {
"aws-lambda": "^1.0.7"
}
}
2023-07-25T08:22:51.456Z undefined ERROR Uncaught Exception
{
"errorType": "TypeError",
"errorMessage": "Cannot read properties of undefined (reading 'filename')",
"stack": [
"TypeError: Cannot read properties of undefined (reading 'filename')",
" at resolve (/var/task/dist/index.js:394337:50)",
" at module2.exports (/var/task/dist/index.js:394354:25)",
" at node_modules/app-root-path/index.js (/var/task/dist/index.js:394381:23)",
" at __require (/var/task/dist/index.js:13:50)",
" at node_modules/jsreport-core/lib/reporter.js (/var/task/dist/index.js:394636:19)",
" at __require (/var/task/dist/index.js:13:50)",
" at node_modules/jsreport-core/index.js (/var/task/dist/index.js:398814:20)",
" at __require (/var/task/dist/index.js:13:50)",
" at dist/src/lib/download_service.js (/var/task/dist/index.js:573619:20)",
" at __require (/var/task/dist/index.js:13:50)",
" at dist/src/chargingSessions/invoices.js (/var/task/dist/index.js:573714:30)",
" at __require (/var/task/dist/index.js:13:50)",
" at dist/src/chargingSessions/router.js (/var/task/dist/index.js:573851:22)",
" at __require (/var/task/dist/index.js:13:50)",
" at dist/src/setupRoute.js (/var/task/dist/index.js:621973:21)",
" at __require (/var/task/dist/index.js:13:50)",
" at Object.<anonymous> (/var/task/dist/index.js:622837:20)",
" at Module._compile (node:internal/modules/cjs/loader:1198:14)",
" at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)",
" at Module.load (node:internal/modules/cjs/loader:1076:32)",
" at Function.Module._load (node:internal/modules/cjs/loader:911:12)",
" at Module.require (node:internal/modules/cjs/loader:1100:19)"
]
}
I have installed the jsreport-core packages "^2.10.1" in my Node App and deployed on my AWS Lambda services. During Deployment no error throws , after the deployment below error throws and my application got crash on lambda function. Im not sure where i can find the solution or what is the root cause of this.
ERROR Uncaught Exception
{
"errorType": "TypeError",
"errorMessage": "Cannot read properties of undefined (reading 'filename')",
"stack": [
"TypeError: Cannot read properties of undefined (reading 'filename')",
" at resolve (/var/task/dist/index.js:394335:50)",
" at module2.exports (/var/task/dist/index.js:394352:25)",
" at node_modules/app-root-path/index.js (/var/task/dist/index.js:394379:23)",
" at __require (/var/task/dist/index.js:13:50)",
" at node_modules/jsreport-core/lib/reporter.js (/var/task/dist/index.js:394634:19)",
" at __require (/var/task/dist/index.js:13:50)",
" at node_modules/jsreport-core/index.js (/var/task/dist/index.js:398812:20)",
" at __require (/var/task/dist/index.js:13:50)",
" at dist/src/lib/download_service.js (/var/task/dist/index.js:573617:20)",
" at __require (/var/task/dist/index.js:13:50)",
" at dist/src/chargingSessions/invoices.js (/var/task/dist/index.js:573710:30)",
" at __require (/var/task/dist/index.js:13:50)",
" at dist/src/chargingSessions/router.js (/var/task/dist/index.js:573848:22)",
" at __require (/var/task/dist/index.js:13:50)",
" at dist/src/setupRoute.js (/var/task/dist/index.js:621827:21)",
" at __require (/var/task/dist/index.js:13:50)",
" at Object.<anonymous> (/var/task/dist/index.js:622691:20)",
" at Module._compile (node:internal/modules/cjs/loader:1198:14)",
" at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)",
" at Module.load (node:internal/modules/cjs/loader:1076:32)",
" at Function.Module._load (node:internal/modules/cjs/loader:911:12)",
" at Module.require (node:internal/modules/cjs/loader:1100:19)"
]
}
Help me to find the solution on this , Thanks in advance folks