mottosson mottosson - 1 year ago 138
Javascript Question

Class has or is using name 'SafeUrl' from external module but cannot be named

I'm using

to put links to blobURL's on the page. This works just fine as long as I don't AoT compile the project.

import {DomSanitizer} from '@angular/platform-browser';

export class AppComponent {
constructor(private sanitizer: DomSanitizer) {

sanitize(url: string) {
return this.sanitizer.bypassSecurityTrustUrl(url);

The sanitize function takes a URL like this:


If I use AoT compilation I get this error message:

Module build failed: Error: /.../src/app/app.component.ts (18,3):
Return type of public method from exported class has or is using name
'SafeUrl' from external module
but cannot be named.)

I'm using CLI with Angular 2.1.0

Anybody knows how I can circumvent this problem? Or should it be reported as a bug?

Answer Source

So it seems I had to add a return type of SafeUrl to the method

  sanitize(url: string):SafeUrl {
    return this.sanitizer.bypassSecurityTrustUrl(url);

Big thanks to alxhub

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download