NativeScript / nativescript-angular

Integrating NativeScript with Angular
http://docs.nativescript.org/angular/tutorial/ng-chapter-0
Apache License 2.0
1.21k stars 241 forks source link

[ANGULAR 9] - ERROR TypeError: null is not an object (evaluating 'view.root.sanitizer.sanitize' #2246

Open mapo80 opened 4 years ago

mapo80 commented 4 years ago

Environment Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

Describe the bug

To Reproduce I've migrate my app from Ng 8 to Ng 9 and I have on console this error:

CONSOLE ERROR file: node_modules/@angular/core/fesm5/core.js:4127:0: ERROR TypeError: null is not an object (evaluating 'view.root.sanitizer.sanitize')

Error is here, view.root.sanitizer is null function setElementStyle(view, binding, renderNode, name, value) { var renderValue = view.root.sanitizer.sanitize(SecurityContext.STYLE, value);

To fix this I've added this on my webpack config:

    config.module.rules.unshift({
        test: /@angular\/core\/fesm5\/core\.js$/,
        use: [{
            loader: 'string-replace-loader',
            options: {
            search: 'var renderValue = view.root.sanitizer.sanitize(SecurityContext.STYLE, value);',
            replace: 'if (view.root.sanitizer == null) { return; }\n var renderValue = view.root.sanitizer.sanitize(SecurityContext.STYLE, value);',
            strict: true,
            },
        }],
    });   

This is a workaround, Is there a better way to solve this problem?

Weiee commented 3 years ago

i've met the same question, do you find an answer to it ?