enyojs / enyo

A JavaScript application framework emphasizing modularity and encapsulation
1.94k stars 281 forks source link

Using XML-JS with EnyoJS #1477

Open trssssrt opened 6 years ago

trssssrt commented 6 years ago

Hey,

I apologize if this is posted in the wrong place, but looking at the XML-JS's Quick Start example we have

var convert = require('xml-js');
            var xml =
                '<?xml version="1.0" encoding="utf-8"?>' +
                '<note importance="high" logged="true">' +
                '    <title>Happy</title>' +
                '    <todo>Work</todo>' +
                '    <todo>Play</todo>' +
                '</note>';
            var op = { compact: true, spaces: 4 };
            var result1 = convert.xml2json(xml, op);
            console.log(result1);

Converting back,


        console.log(convert. json2xml(result1, op));

Which gives the following error:

json2xml.js:4 Uncaught ReferenceError: Buffer is not defined
    at Object.module.exports [as json2xml] (json2xml.js:4)
    at enyoConstructor.handleExport (DataControl.js:357)
    at enyoConstructor.dispatch (Component.js:779)
    at enyoConstructor.dispatchEvent (Component.js:687)
    at enyoConstructor.dispatchEvent (Control.js:1311)
    at enyoConstructor.dispatchBubble (Component.js:734)
    at enyoConstructor.bubbleUp (Component.js:645)
    at enyoConstructor.dispatchEvent (Component.js:716)
    at enyoConstructor.dispatchEvent (Control.js:1311)
    at enyoConstructor.dispatchBubble (Component.js:734)
    at enyoConstructor.bubble (Component.js:617)
    at Object.dispatchBubble (dispatcher.js:161)
    at Object.dispatch (dispatcher.js:115)
    at Object.sendTap (gesture.js:142)
    at Object.up (gesture.js:102)
    at Object.mouseup (gesture.js:295)

Other than what's up there, I grabbed xml-js through

npm install --save xml-js

Thoughts?

webOS101 commented 6 years ago

Are you running this on an older version of IE by any chance? You may need to require Enyo's Buffer shim (or, apply your own).

trssssrt commented 6 years ago

I'm using Chrome. How do I access Enyo's Buffer?

webOS101 commented 6 years ago

Sorry, turns out I was having a bit of a brain fart. It was Blob that we had polyfilled for older browsers. I think given that it's trying to access Buffer that it is getting confused about being packed by our node build tools. Is there some way to force the library to use the browser version? Buffer is a node concept.