Hi,
Am trying to use “aspose.cells for nodejs via Java” npm package for my Typescript project.
I use one third party library(playwright-bdd) in my project and had to execute a command from it to generate test files. When trying to execute, node is not exiting properly and due to this its not moving to the next task in my job in pipeline. I did debug in local and got to see that aspose.cells nodejs via Java npm package is causing the problem.
To reproduce it, Can you try to add the below 2 lines in a file.js and try running ‘node file.js’ and we can see that the node is not terminating properly. Can you check and let me know if we can have any work around or let me know if am wrong anywhere ?
var aspose = aspose || {};
aspose.cells= require(“aspose.cells”);
@charanmba24
It seems you are experiencing an issue with the “aspose.cells for nodejs via Java” npm package in your TypeScript project, specifically related to Node.js not terminating properly after executing your script. This can sometimes occur due to lingering asynchronous operations or unhandled promises in the code.
Here are a few suggestions to troubleshoot and potentially resolve the issue:
-
Ensure Proper Cleanup: Make sure that all resources are properly disposed of after use. If you are using any asynchronous functions, ensure that they are awaited or properly handled to avoid leaving open handles.
-
Check for Unresolved Promises: If there are any promises that are not resolved or rejected, Node.js may not exit. You can add a listener for unhandled promise rejections to help identify if this is the case:
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
});
-
Use process.exit()
: As a last resort, you can forcefully exit the process by calling process.exit()
. However, this should be used cautiously as it will terminate the Node.js process immediately, potentially leaving some operations incomplete.
-
Debugging: You can add logging statements before and after the require
statement to see if the issue is specifically related to loading the Aspose.Cells module or if it occurs later in your code.
-
Check for Known Issues: Review the documentation and any known issues related to the “aspose.cells for nodejs via Java” package. Sometimes, specific versions may have bugs that could cause such behavior.
If the problem persists, consider reaching out to the Aspose support team with detailed information about your environment and the specific code you are using. They may have additional insights or workarounds for this issue.
If you have any further questions or need additional assistance, feel free to ask!
@charanmba24
Which version are you currently using? Starting from v24.7.0, Aspose.Cells for Node.js via Java has been migrated to aspose.cells.java. Please check: the Note.
Please refer to the following example code:
var aspose = aspose || {};
aspose.cells = require("aspose.cells.java");
console.log(aspose.cells.CellsHelper.getVersion());
var workbook = new aspose.cells.Workbook(aspose.cells.FileFormatType.XLSX);
workbook.getWorksheets().get(0).getCells().get("A1").putValue("test data");
workbook.save("out_hello_nodejs_java.xlsx");
console.log("hello world");
@charanmba24
Please try the following code:
var aspose = aspose || {};
aspose.cells = require("aspose.cells");
var workbook = new aspose.cells.Workbook("example.xlsx");
var options = new aspose.cells.PdfSaveOptions();
options.setOnePagePerSheet(true);
workbook.save("output.pdf", options);
var java = require("java");
java.callStaticMethodSync('java.lang.System', 'exit', 0);
You can solve this problem by calling the exit method explicitly. Thanks.
Hi @John.He - Yes. Am using aspose.cells.java version 24.7.0. and I still have the issue.
Hi @Nick.Liu - Am running the npx task from a third party library that generates my test files. But when I have the aspose.cells.java, I still see that node job is not exiting properly as shown below.
I tried giving your below code inside the aspose functions I have, but, still my npx task is not exited as mentioned above.
var java = require(“java”);
java.callStaticMethodSync(‘java.lang.System’, ‘exit’, 0);
image.png (3.6 KB)
Also, I tried giving outside the function, the node job is exiting, but it fails to create test files from the npx task that I run.
Is there any other work around ?
@charanmba24
Can the npx task exit normally by simply adding the following statement without using the Aspose.Cells for Node.js via Java apis?
var java = require("java");
java.callStaticMethodSync('java.lang.System', 'exit', 0);
@charanmba24
I create a simple project and run with npx bddgen
cmd, it works fine. Please check the attachments.
bddgen-example.zip (954 Bytes)
bddgen-example.png (503 Bytes)
It would be very helpful if you could provide your project to reproduce the issue. Thanks.
Hi @Nick.Liu - Yes. This seems like it exits the node, but, the ‘npx bddgen’ will generate an out folder ‘.features-gen/*.spec.js’ with test files. Its missing to generate this folder and files.
image.png (1.7 KB)
Hi @John.He - Yes. Without using the aspose.cells for Nodejs via java, the ‘npx bddgen’ works fine.
Can you suggest any work around for this issue ?
@charanmba24,
We appreciate your feedback and screenshot.
We will investigate the issue and respond to you soon.
@charanmba24
I’m not familiar with playwright-bdd. Please provide a simple project(playwright.config.ts, features) to reproduce the issue. Thanks.
@charanmba24
This problem is essentially caused by the node-java bridge event loop. Since node-java bridge is a third-party library, we cannot modify and submit it on npm.js. So we can only modify and compile it locally according to the following steps:
- Open the java.cpp file in the node_modules\java\src directory and comment out the following line of code:
uv_async_init(uv_default_loop(), &uvAsync_dynamicProxyJsCall, uvAsyncCb_dynamicProxyJsCall);
- cd node_modules\java, execute
node-gyp build
- Remove these two lines in your code:
var java = require("java");
java.callStaticMethodSync('java.lang.System', 'exit', 0);
If there are still problems, please provide detailed file content and execution steps. Thank you.