Page 1 of 1

Cannot find module

Posted: Mon Dec 06, 2021 3:14 pm
by bkromer
Hey there,

this is my first SwitchScript with Node.js envolved.

I want to use a third party package from npm that can validate XML against a XSD.

I picked this one https://www.npmjs.com/package/libxmljs2-xsd.

My code:

Code: Select all

const xsd = require('libxmljs2-xsd');
const fs = require('fs');

async function jobArrived(s, flowElement, job) {
    let xsdPath = await flowElement.getPropertyStringValue("xsdPath");
    await job.log(LogLevel.Info,'%1',[xsdPath]);
    //const jobName = await getName();
    const jobTempPath = await job.get(AccessLevel.Read);
    const schema = await xsd.parseFile(xsdPath);
    let documentString = await fs.readdirSync(jobTempPath)
    let validationErrors = await schema.validate(documentString);
    if (validationErrors === null){
        job.sendToData(Connection.Level.Success);
    } else{
        job.log(LogLevel.Info,'%1',[validationErrors]);
        job.sendToData(Connection.Level.Warning);
    }    
}

I have a Package.json:
....
"dependencies": {
"libxmljs2-xsd": "^0.28.0"
}
}
I did "npm install libxmljs2-xsd" as documented.

And also my propertie xsdPath is setup:
Bildschirmfoto 2021-12-06 um 15.05.02.png
Bildschirmfoto 2021-12-06 um 15.05.02.png (139.44 KiB) Viewed 2371 times
The errormessage says:
Cannot find module 'C:\Users\myservername\AppData\Roaming\Enfocus\SwitchProcessorService\cache\031f213823b89b1725061c482e50b2e67622a913232442f6e415d8f18ec5c267\1638795351\node_modules\libxmljs2-xsd' Require stack: - C:\Program Files\Enfocus\Enfocus Switch\ScriptExecutor\NodeScriptExecutor.js
So what am I missing here? Is the module not supported? How can I know?

Re: Cannot find module

Posted: Mon Dec 06, 2021 10:18 pm
by jan_suhr
Do you have the same name on the script file as on the icon file?
Or just set the icon to None and try if it works then.

Re: Cannot find module

Posted: Thu Dec 09, 2021 5:12 pm
by bkromer
Deactivating the Icon didn't work. I wrote another script with the "axios" package and "form-data" and this one worked perfectly so I'm guessing "libxmljs2-xsd" doesn't run on the version of nodeJS installed with switch.

There is really no good package to validate XML against XSD in npm.