XML Parser Error: TypeError: fs.readFileSync is not a function
Closed this issue · 5 comments
in linux fs not function correct
@1.0.0 /home//Documentos/Workspace/
└── pixl-xml@1.0.13 extraneous
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.2.4
the console show XML Parser Error: TypeError: fs.readFileSync is not a function
not work
I cannot explain. fs.readFileSync
is a built-in function that Node.js provides as part of the language core. If this function is somehow missing on your system, then something is very, very wrong with Node.js itself. I don't believe this is a problem with pixl-xml.
It's likely that he's not building for node but for a js env which doesn't have fs
builtin.
For instance, this library breaks if trying to run in a browser context (built with something like webpack). Try it out with the webpack config:
module.exports = {
entry: './src/index.js',
output: {
filename: 'main.js',
path: 'dist'
}
};
it won't work. And then again with target applied:
module.exports = {
target: 'node',
entry: './src/index.js',
output: {
filename: 'main.js',
path: 'dist'
}
};
It does work.
Anybody finding this issue for this problem, you're better off adding externals to your webpack config:
externals: {
fs: 'fs'
}
Hi, so I need to use this tool in the browser.
The fs module was used in case the xml input is a file, but for my case it's never a file, always a response to a query. So I just commented the condition and the import.
So my monkey-patched version will now work in the browser.
I think I'll try and re-implement the feature with window.FileReader, I think that could work, then I'll PR it for you.
I have a browser-ready version here: https://github.com/jhuckaby/pixl-webapp/blob/master/js/xml.js
Docs here: https://github.com/jhuckaby/pixl-webapp/blob/master/docs/xml.md
The main thing I wanted was the bucklescript binding here,
https://gitlab.com/NicolasJouanin/bs-pixl-xml/tree/master
So I think I'll still use this version for the moment. Rather than mess with it, I'll probably write bindings for the new project instead.
Thanks a lot.