I have been working on an angular 5 application where I needed to incorporate the dmn-js library. Unfortunately, this library does not come with typings available. To tackle this issue, I followed the guidelines provided in the Angular-CLI wiki regarding how to include third-party libraries without typings under the section titled "If the library doesn't have typings available at @types/, you can still use it by manually adding typings for it:"
After following these steps, my code has now been updated as follows:
src/typings.d.ts
/* SystemJS module definition */
declare var module: NodeModule;
declare module 'dmn-js';
interface NodeModule {
id: string;
}
src/app/app.component.ts
import { Component, OnInit } from '@angular/core';
import {HttpClient} from '@angular/common/http';
import * as DmnJS from 'dmn-js';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'DMN';
constructor(private http: HttpClient){
}
ngOnInit(): void {
var viewer = new DmnJS ({ container: 'body' });
var dmnXML; //DMN 1.1 xml
viewer.importXML(dmnXML, this.handleError);
}
handleError(err: any) {
if (err) {
console.warn('Ups, error: ', err);
}else {
console.log('rendered');
}
}
load(): void {
const url = '/assets/dish-decision.dmn';
this.http.get(url, {
headers: {observe: 'response'}, responseType: 'text'
}).subscribe(
(x: any) => {
console.log('Fetched XML, now importing: ', x);
//this.modeler.importXML(x, this.handleError);
},
this.handleError
);
}
save(): void {
//this.modeler.saveXML((err: any, xml: any) => console.log('Result of saving XML: ', err, xml));
}
}
However, when I attempt to compile the code, I encounter the following error message. Despite having followed all the necessary steps, I am uncertain about what needs to be done to address this issue.
ERROR in ./node_modules/dmn-js-drd/lib/Viewer.js
Module parse failed: Unexpected token (175:4)
You may need an appropriate loader to handle this file type.
| additionalModules,
| canvas,
| ...additionalOptions
| } = options;
|
ERROR in ./node_modules/dmn-js-shared/lib/base/Manager.js
Module parse failed: Unexpected token (292:16)
You may need an appropriate loader to handle this file type.
| }
|
| _viewsChanged = () => {
| this._emit('views.changed', {
| views: this._views,
ERROR in ./node_modules/dmn-js-decision-table/lib/Viewer.js
Module parse failed: Unexpected token (75:6)
You may need an appropriate loader to handle this file type.
| modules,
| additionalModules,
| ...config
| } = options;
|
ERROR in ./node_modules/dmn-js-literal-expression/lib/Viewer.js
Module parse failed: Unexpected token (77:6)
You may need an appropriate loader to handle this file type.
| modules,
| additionalModules,
| ...config
| } = options;
|
webpack: Failed to compile.