问题
Trying to include the sax parser and running into difficulties [parser.ts].
import sax = require("sax");
export class MyParser {
//my parser code
}
When I try to use it [app.component.ts]:
import {MyParser} from './parser'
...
constructor(private http: Http, private parser: MyParser) {}
I get this error
Evaluating http://localhost:3000/sax
Which I know means SystemJS cannot find the module. Sax is installed in node_modules and listed in package.json. I've installed typings using
typings install --ambient sax
But getting lots of duplicate identifier warnings even though my tsconfig.json is excluding
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
Lastly, isaacs uses code like this in his examples
tag.parent
tag.children
This isn't supported by the typing (d.ts).
Does anyone have a working install of sax with TS and ng2?
回答1:
The error you have is at runtime. So I think that you could try to configure SystemJS this way:
<script>
System.config({
paths: {
sax: './node_modules/sax/lib/sax.js'
}
})
</script>
This way you will be able to import Sax:
import {SAXParser} from 'sax';
来源:https://stackoverflow.com/questions/35971560/how-to-import-sax-parser-into-angular2-using-typescript