Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular library build error "Cannot read properties of null (reading 'render')" #4503

Closed
JMRCGuedes opened this issue May 19, 2022 · 8 comments · Fixed by #4510
Closed

Angular library build error "Cannot read properties of null (reading 'render')" #4503

JMRCGuedes opened this issue May 19, 2022 · 8 comments · Fixed by #4510

Comments

@JMRCGuedes
Copy link

JMRCGuedes commented May 19, 2022

Rollup Version

2.74.0 (latest)

Operating System (or Browser)

Windows 10

Node Version (if applicable)

16.15.0

Link To Reproduction

not applicable

Expected Behaviour

Passing the ng build

Actual Behaviour

Error:
Running ng build on angular library gives the following error
Cannot read properties of null (reading 'render')

image

Disclaimer:
Being this an enterprise project I can´t provide more information but I think that the problem is related to the changes made by using the optional chaining operator

image

Workaround:

By adding the following in the package.json devDependencies, it works fine:

"rollup": "2.72.1",
"@rollup/plugin-json": "4.1.0",
"@rollup/plugin-node-resolve": "13.3.0"

@digaus
Copy link

digaus commented May 19, 2022

@lukastaegert

Same issues. Not only that but compilation now produces different and wrong results when not using optional chaining!

This is a major issue for us and might break other libs and applications because it is not noticed while compiling. It completely drops use cases and passes void 0 to functions instead of the actual data...

Adding "rollup": "2.73.0" to the package.json fixes this for now...

Source Code:

  public updateLookupById(lookupName: string, id: any, updateLookup?: boolean): Promise<any> {
        const lookup: LookupBean = this.lookupMap.get(lookupName);
        return new Promise<any>((resolve: any): any => {
            if (lookup) {
                if (!!this.blocked.get(lookup.url + '/' + id)) {
                    this.blocked.get(lookup.url + '/' + id).subscribe((dataHolder: any) => {
                        let result: any;
                        if (lookup.withDataHolder) {
                            result = dataHolder.data[ 0 ];
                        } else {
                            result = dataHolder;
                        }
                        if (updateLookup) {
                            this.updateLookupWithObject(lookupName, result);
                        }
                        resolve(result);
                    }, () => resolve(null));
                } else {
                    const sub: any = this.myHttpClientService.get(lookup.url + '/' + id, null, true).pipe(share());
                    this.blocked.set(this.lookupMap.get(lookupName).url + '/' + id, sub);
                    sub.subscribe((dataHolder: any) => {
                        let result: any;
                        if (lookup.withDataHolder) {
                            result = dataHolder.data[ 0 ];
                        } else {
                            result = dataHolder;
                        }
                        if (updateLookup) {
                            this.updateLookupWithObject(lookupName, result);
                        }
                        this.blocked.delete(lookup.url + '/' + id);
                        resolve(result);
                    }, () => resolve(null));
                }
            } else {
                console.warn('Lookup mit dem lookupNamen "' + lookupName + '" konnte nicht gefunden werden');
                console.warn('Geladene Lookups: ' + Array.from(this.lookupMap.keys()).toString());
                resolve(null);
            }
        });
    }

Previous compilation:

               updateLookupById(pe, st, Ot) {
                    const Kt = this.lookupMap.get(pe);
                    return new Promise(fn=>{
                        if (Kt)
                            if (this.blocked.get(Kt.url + "/" + st))
                                this.blocked.get(Kt.url + "/" + st).subscribe(Pn=>{
                                    let $n;
                                    $n = Kt.withDataHolder ? Pn.data[0] : Pn,
                                    Ot && this.updateLookupWithObject(pe, $n),
                                    fn($n)
                                }
                                , ()=>fn(null));
                            else {
                                const Pn = this.myHttpClientService.get(Kt.url + "/" + st, null, !0).pipe((0,
                                ve.B)());
                                this.blocked.set(this.lookupMap.get(pe).url + "/" + st, Pn),
                                Pn.subscribe($n=>{
                                    let Qn;
                                    Qn = Kt.withDataHolder ? $n.data[0] : $n,
                                    Ot && this.updateLookupWithObject(pe, Qn),
                                    this.blocked.delete(Kt.url + "/" + st),
                                    fn(Qn)
                                }
                                , ()=>fn(null))
                            }
                        else
                            console.warn('Lookup mit dem lookupNamen "' + pe + '" konnte nicht gefunden werden'),
                            console.warn("Geladene Lookups: " + Array.from(this.lookupMap.keys()).toString()),
                            fn(null)
                    }
                    )
                }

Current compilation:

                updateLookupById(pe, st, Ot) {
                    const Kt = this.lookupMap.get(pe);
                    return new Promise(fn=>{
                        if (Kt)
                            if (this.blocked.get(Kt.url + "/" + st))
                                this.blocked.get(Kt.url + "/" + st).subscribe(Pn=>{
                                    Ot && this.updateLookupWithObject(pe, void 0),
                                    fn(void 0)
                                }
                                , ()=>fn(null));
                            else {
                                const Pn = this.myHttpClientService.get(Kt.url + "/" + st, null, !0).pipe((0,
                                ve.B)());
                                this.blocked.set(this.lookupMap.get(pe).url + "/" + st, Pn),
                                Pn.subscribe(qn=>{
                                    Ot && this.updateLookupWithObject(pe, void 0),
                                    this.blocked.delete(Kt.url + "/" + st),
                                    fn(void 0)
                                }
                                , ()=>fn(null))
                            }
                        else
                            console.warn('Lookup mit dem lookupNamen "' + pe + '" konnte nicht gefunden werden'),
                            console.warn("Geladene Lookups: " + Array.from(this.lookupMap.keys()).toString()),
                            fn(null)
                    }
                    )
                }

@lukastaegert
Copy link
Member

lukastaegert commented May 19, 2022

Rollup does not inject void 0. Can you give the result without a minifier that completely scrambles the code? Or create some kind of reproduction that I can work with?

@lukastaegert
Copy link
Member

And for the initial error which seems completely unrelated to the second one (maybe it should be a separate issue?): If you cannot give a reproduction, is there a way to print the stack trace of the error? It would seem very odd to me that optional chaining would cause an error Cannot read properties of null, but maybe the ? is missing in another place?

@lukastaegert
Copy link
Member

In any case, I feel with you, but I need reproductions, not code snippets.

@digaus
Copy link

digaus commented May 19, 2022

Rollup does not inject void 0. Can you give the result without a minifier that completely scrambles the code? Or create some kind of reproduction that I can work with?

Here you can see that result is never assigned, will see if I can make some small reproduction repo

  updateLookupById(lookupName, id, updateLookup) {
        const lookup = this.lookupMap.get(lookupName);
        return new Promise((resolve) => {
            if (lookup) {
                if (!!this.blocked.get(lookup.url + '/' + id)) {
                    this.blocked.get(lookup.url + '/' + id).subscribe((dataHolder) => {
                        let result;
                        if (updateLookup) {
                            this.updateLookupWithObject(lookupName, result);
                        }
                        resolve(result);
                    }, () => resolve(null));
                }
                else {
                    const sub = this.myHttpClientService.get(lookup.url + '/' + id, null, true).pipe(share());
                    this.blocked.set(this.lookupMap.get(lookupName).url + '/' + id, sub);
                    sub.subscribe((dataHolder) => {
                        let result;
                        if (updateLookup) {
                            this.updateLookupWithObject(lookupName, result);
                        }
                        this.blocked.delete(lookup.url + '/' + id);
                        resolve(result);
                    }, () => resolve(null));
                }
            }
            else {
                console.warn('Lookup mit dem lookupNamen "' + lookupName + '" konnte nicht gefunden werden');
                console.warn('Geladene Lookups: ' + Array.from(this.lookupMap.keys()).toString());
                resolve(null);
            }
        });
    }

@digaus
Copy link

digaus commented May 19, 2022

#4504

Made seperate issue and added reproduction repo

@JMRCGuedes
Copy link
Author

JMRCGuedes commented May 20, 2022

related to
#4506
Fixed in 2.74.1

@lukastaegert
Copy link
Member

I created a new PR #4510 that reimplements parameter tree-shaking in a more conservative way. Could you verify that this PR works for you via npm install rollup/rollup#parameter-defaults?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants