snowdd1 / knx-ets5-ga-reader

Reader for ETS5 Group Address Exports (XML format)
5 stars 2 forks source link

Got error with newest Node-Version #2

Open mazl-io opened 2 years ago

mazl-io commented 2 years ago

If you just clone the project, do a npm install and run the script as described in readme.md it will end up with the following error:

node:events:505
      throw er; // Unhandled 'error' event
      ^

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received 'utf-8'
←[90m    at maybeCallback (node:fs:177:3)←[39m
←[90m    at Object.writeFile (node:fs:2118:14)←[39m
    at D:\knx-ets5-ga-reader-master\test-file.js:54:8
    at Parser.<anonymous> (D:\knx-ets5-ga-reader-master\node_modules\←[4mxml2js←[24m\lib\parser.js:304:18)
←[90m    at Parser.emit (node:events:527:28)←[39m
    at SAXParser.onclosetag (D:\knx-ets5-ga-reader-master\node_modules\←[4mxml2js←[24m\lib\parser.js:262:26)
    at emit (D:\knx-ets5-ga-reader-master\node_modules\←[4msax←[24m\lib\sax.js:624:35)
    at emitNode (D:\knx-ets5-ga-reader-master\node_modules\←[4msax←[24m\lib\sax.js:629:5)
    at closeTag (D:\knx-ets5-ga-reader-master\node_modules\←[4msax←[24m\lib\sax.js:889:7)
    at SAXParser.write (D:\knx-ets5-ga-reader-master\node_modules\←[4msax←[24m\lib\sax.js:1436:13)
Emitted 'error' event on Parser instance at:
    at Parser.exports.Parser.Parser.parseString (D:\knx-ets5-ga-reader-master\node_modules\←[4mxml2js←[24m\lib\parser.js:327:16)
    at Parser.parseString (D:\knx-ets5-ga-reader-master\node_modules\←[4mxml2js←[24m\lib\parser.js:5:59)
    at D:\knx-ets5-ga-reader-master\test-file.js:25:10
←[90m    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)←[39m {
  code: ←[32m'ERR_INVALID_CALLBACK'←[39m
}

To be compatible with newest node version and the current fs package you need to specify a callback function like:

fs.writeFile(__dirname + '/'+ config.niceReadableTestFile,  JSON.stringify(groupAddresses, undefined, 4), 'utf-8', function(err) {
     if(err) {
          console.log('Cant write to file');
     }
});
mazl-io commented 2 years ago

Unfortunately I am unable to add a pull request with a fix for it.