External module function error: "Cannot read properties of undefined (reading 'split')"

Describe the issue/error/question

I am using the following external module RDP Crystal EDI Library in a isolated code node to parse EDI transaction data. I am able to run this code locally, outside of n8n, successfully. When trying to run this code from a Desktop instance of a n8n code module I run into the error below. The validator.validate function from this library throws this error. I am able to use other functions from this library. The following is a link to the rules file used in the code.

What is the error message (if any)?

TypeError: Cannot read properties of undefined (reading 'split')
    at ExecutionError.populateFromStack (/Applications/n8n.app/Contents/Resources/app/node_modules/n8n-nodes-base/dist/nodes/Code/ExecutionError.js:20:38)
    at new ExecutionError (/Applications/n8n.app/Contents/Resources/app/node_modules/n8n-nodes-base/dist/nodes/Code/ExecutionError.js:17:14)
    at Sandbox.runCodeAllItems (/Applications/n8n.app/Contents/Resources/app/node_modules/n8n-nodes-base/dist/nodes/Code/Sandbox.js:60:19)
    at async Object.execute (/Applications/n8n.app/Contents/Resources/app/node_modules/n8n-nodes-base/dist/nodes/Code/Code.node.js:74:25)
    at async Workflow.runNode (/Applications/n8n.app/Contents/Resources/app/node_modules/n8n-workflow/dist/src/Workflow.js:645:28)
    at async /Applications/n8n.app/Contents/Resources/app/node_modules/n8n-core/dist/src/WorkflowExecute.js:562:53

Please share the workflow (Single code module)

const edi = require('rdpcrystal-edi-library');

const fs = require('fs');

//Load 5010 834 input file
const edi834input = "ISA*00*……….*01*SECRET….*ZZ*SUBMITTERS.ID..*ZZ*RECEIVERS.ID…*030101*1253*^*00501*000000905*1*T*:~\n"+
"GS*Hk*SENDER CODE*RECEIVERCODE*19991231*0802*1*X*005010X279A1~\n"+
"NM1*PR*2*ABC COMPANY*****PI*842610001~\n"+
"NM1*1P*2*BONE AND JOINT CLINIC*****SV*2000035~\n"+
let validator = new edi.EDIValidator();

const validate = (ediInput) => {
    //Create a validator instance

    //Load a 5010 270 Validation Rules File
    let validationRules = fs.readFileSync('/Users/don/Desktop/Rules_5010_834_005010X220A1.Rules').toString();
    //Set the validation rules data
    //Validation rules are found in the RDPCrystalInstallation\Validation Rules directory
    validator.EDIRulesFileData = validationRules;

    validator.EDIDataString = ediInput;


    //Get the EDI document loaded into memory
    let loadedEDIFile = validator.EDILightWeightDocument;

    console.log("Validation Errors count: ", validator.Errors.Count);

    //Get all errors from the EDI data
    for (let i = 0; i < validator.Errors.Count; i++) {
        let error = validator.Errors.getItem(i);
                Type: "Error",
                Line: error.LineNumber,
                Transaction: "",
                SnipLevel: error.SnipLevel,
                Message: error.Message,
                Loop: error.Loop,
                Segment: error.Segment,
                Element: error.ElementOrdinal,
                Composite: error.CompositeElementOrdinal,
                Description: error.Description,
                Ordinal: error.SegmentOrdinal

const splitEDIInput = (ediInput) => {

    let original = ediInput;

    //Create a new EDIFileSplitter
    let splitter = new edi.EDIFileSplitter();

    //Split the document at the ST header
    splitter.FileSplitLevel = edi.FileSplitLevel.HEADER;

    //Put 1 ST-SE loop in each file
    splitter.NumberOfItemsPerFile = 1;

    //Split the document
    let splitDocs = splitter.split(original);

    console.log("First Split Document");



return null;

Information on your n8n setup

  • n8n version: 1.7.0
  • Database you’re using (default: SQLite): SQLite
  • Running n8n with the execution process [own(default), main]: own
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: desktop app

Hi @dnqwn, I am afraid I am not familiar with this library. Seeing you have it working outside of n8n, perhaps you can simply call an existing script through n8n’s Execute Command node?