archi-scripting-plugin: CommonJS settings cause linked JS file to not load
Since jArchi 1.6 we have two new properties:
System.setProperty("polyglot.js.commonjs-require", "true");
System.setProperty("polyglot.js.commonjs-require-cwd", ArchiScriptPlugin.INSTANCE.getPreferenceStore().getString(IPreferenceConstants.PREFS_SCRIPTS_FOLDER));
However, some imported JS files no longer work.
- Add
papaparse.jsto alibfolder in your jArchi scripts folder papaparse.js.zip - Run this simple script:
console.show();
console.clear();
load(__DIR__ + "lib/papaparse.js");
console.log("> Loaded Papa Parse");
console.log(Papa);
> Loaded Papa Parse
org.graalvm.polyglot.PolyglotException: ReferenceError: "Papa" is not defined
@jbsarrodie WDYT?
(PapaParse source - https://www.papaparse.com/)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (18 by maintainers)
And BTW, I’ll update the wiki page with more information soon too.
Done. 😉
Thank you for your analysis, you’re right. In fact, Papaparse authors tried to make their lib “intelligent”, and when the code is loaded, it tries to figure out in which context (browser, node.js or other) it has been executed. Unfortunately, there is no perfect method for that and their approach has some side effects in this case. So this is not an issue with jArchi itself, but a side effect of how this very specific javascript lib has been coded. And that’s the reason why I didn’t experienced this issue during my tests (I’m using several other libs with no issues, and I didn’t tested the one script I have which relies on Papaparse).
I think the best option is to document our findings in a wiki page and update the Changelog to make sure people facing the issue understand it and find the quick solution.
Speaking about the solution…
There is an easier fix:
require()can load modules using their absolute path. So no need for all these steps, simply replaceby
IMHO, we don’t need to add such option only to solve an issue related to the way a specific lib has been written. I’d better keep jArchi 1.6 as it is and let people change one line their code.
I’ll look at it tonight.
JB