I'm trying to require the xml-js module (https://www.npmjs.com/package/xml-js) to do some XML parsing in my existing Electron + Typescript project.
What I'm slightly confused about is why it is throwing an error.
First of all, the tsconfig.json file is the following:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "dist"
},
"exclude": [
"node_modules"
]
}
the relevant part of the systemjs config is here:
paths: {
'npm:': 'node_modules/'
},
map: {
'xml-js': 'npm:xml-js'
},
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
So the module is located in node_modules/xml-js (like many others).
When I build my application, I get the following error:
file://<path>/Documents/projectFolder/electron-angular2-rc6/ng2-electron/node_modules/xml-js Failed to load resource: net::ERR_FILE_NOT_FOUND
and :
index.html:18 Error: (SystemJS) XHR error loading file://<path>/Documents/projectFolder/electron-angular2-rc6/ng2-electron/node_modules/xml-js
I'm attempting to load the module through:
const parser = require("xml-js");
(so, as vanilla JS), in my typescript component (application.component.ts).
The relevant part of my index.html is:
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
document.addEventListener('dragover',function(event){
event.preventDefault();
return false;
},false);
document.addEventListener('drop',function(event){
event.preventDefault();
return false;
},false);
</script>
The module has been installed through:
npm install xml-js --save-dev
And exists in the directory node_modules/xml-js
I have tons of other modules (including rxjs and angular-in-memory-web-api) along with the regular @angular ones: all of them are working properly and throwing no error, but the xml-js one seems to be not working whatsoever.
npm install xml-js --save- instead ofnpm install xml-js --save-devor moving it to the <dependencies> zone?map: { 'xml-js': './node_modules/xml-js/index.js' }or even into its lib sub-foldermap: { 'xml-js': './node_modules/xml-js/lib/index.js' }