2017-05-10 2 views
0

Sein neu installieren, um Winkel 2 Ich versuche Paket zu installieren xml2json aber einige Fehler. Ich habe versucht, ähnliche Fragen geschrieben, aber nichts half mirAngular 2 CLI: Need xml2json Paket

unten sind Dinge, die ich 1) Knoten neueste Version 2) Python 2 ... auch gesetzt env Variablen 3) npm installieren --global --production Fenster installiert haben -build-Tools 4) NPM installieren Knoten-gyp

aber ich bekomme immer noch Fehler. es gibt jede Sequenz tun müssen, i folgen xml2json

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected]^1.0.0 (node_modules\chokidar\node_modules\fsevents): 
 
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) 
 
npm ERR! Windows_NT 10.0.14393 
 
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "xml2json" 
 
npm ERR! node v7.7.4 
 
npm ERR! npm v4.1.2 
 
npm ERR! code ELIFECYCLE 
 

 
npm ERR! [email protected] install: `node-gyp rebuild` 
 
npm ERR! Exit status 1 
 
npm ERR! 
 
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'. 
 
npm ERR! Make sure you have the latest version of node.js and npm installed. 
 
npm ERR! If you do, this is most likely a problem with the node-expat package, 
 
npm ERR! not with npm itself. 
 
npm ERR! Tell the author that this fails on your system: 
 
npm ERR!  node-gyp rebuild 
 
npm ERR! You can get information on how to open an issue for this project with: 
 
npm ERR!  npm bugs node-expat 
 
npm ERR! Or if that isn't available, you can get their info via: 
 
npm ERR!  npm owner ls node-expat 
 
npm ERR! There is likely additional logging output above. 
 

 
npm ERR! Please include the following file with any support request: 
 
npm ERR!  C:\Angular2\XML2JS\npm-debug.log

+0

Versuchen Sie, xml2json zu installieren? oder angular 2 CLI? – Oussa

+0

xml2json in angular2 cli Projekt mit npm –

+0

gibt es eine andere Art und Weise xml2json andere zu verwenden, als npm –

Antwort

1

[Vorschlag] Da Sie verwenden Angular-CLI, kommt es bereits mit einem XML-Dienstprogramm erhalten installiert zu verwenden, aus der Box, https://github.com/Leonidas-from-XIV/node-xml2js

So müssen Sie nichts extra installieren, nur sicherstellen, dass Sie es richtig in Ihre Datei importieren.

Angular 2 Beispiel:

import { Component, OnInit } from '@angular/core'; 
 
import * as xml2js from 'xml2js'; 
 
import * as _ from 'lodash'; 
 

 
@Component({ 
 
    selector: 'app-root', 
 
    templateUrl: './app.component.html', 
 
    styleUrls: ['./app.component.css'] 
 
}) 
 
export class AppComponent implements OnInit { 
 
    title: string; 
 
    xml = `<?xml version="1.0" encoding="UTF-8" ?> 
 
      <page> 
 
      <title>W3Schools Home Page</title> 
 
      </page>`; 
 

 
    ngOnInit() { 
 
    const parser = new xml2js.Parser(); 
 
    parser.parseString(this.xml, (err, result) => { 
 
     console.log(result); 
 
     // result is your javascript parsed object 
 
     // you can access attribut for example with lodash getters 
 
     this.title = _.first(_.get(result, 'page.title')); 
 
    }); 
 
    } 
 
}

+0

Ich habe versucht npm --global --production windows-Build-Tools installieren, aber nicht für mich arbeiten .... können Sie mir bitte geben Folge der Dinge xml2json installiert –

+0

meine python-Version ist 2.7.13 –

+0

do u haben am Beispiel var xml2js = require ('xml2js') zu erhalten; –