Cannot find module

Post Reply
bkromer
Member
Posts: 99
Joined: Thu Jul 11, 2019 10:41 am

Cannot find module

Post 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 2046 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?
Benjamin
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Cannot find module

Post 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.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
bkromer
Member
Posts: 99
Joined: Thu Jul 11, 2019 10:41 am

Re: Cannot find module

Post 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.
Benjamin
Post Reply