[英]Import xml2js in angular4 application
I'm having problems using xml2js in my Angular4 Application.我在 Angular4 应用程序中使用 xml2js 时遇到问题。
I installed it via npm, and imported it like this:我通过 npm 安装它,并像这样导入它:
import {parseString} from "xml2js";
But when I start my application, I get this error:但是当我启动我的应用程序时,我收到此错误:
Failed to load resource: the server responded with a status of 404 (Not Found)
Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:3000/node_modules/xml2js
I also install typings.我也安装打字机。
I'm new to Angular (and Typescript), so i would be glad if someone could help me and explain what I did wrong :)我是 Angular(和 Typescript)的新手,所以如果有人能帮助我并解释我做错了什么,我会很高兴:)
import * as xml2js from 'xml2js';
or或
import { parseString } from 'xml2js';
If don't work, need run如果不工作,需要运行
npm install --save @types/xml2js
npm install --save @types/xml2js
I imported the library exactly as you did with a clean project created using the angular cli and it imports and works fine.我完全按照使用 angular cli 创建的干净项目的方式导入了该库,并且它导入并正常工作。
If you are new to angular I would recommend using the official cli tool for setting up your project, it simplifies a lot of things related to importing packages.如果您不熟悉 angular,我建议您使用官方的 cli 工具来设置您的项目,它简化了很多与导入包相关的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.