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

cant build due to "Optional chaining cannot appear in left-hand side" #2259

Closed
ohabash opened this issue Mar 1, 2022 · 5 comments
Closed

Comments

@ohabash
Copy link

ohabash commented Mar 1, 2022

Type of Issue

[ x] Bug Report

Description

After running ng build my-publishable-module I get an error durring build

✔ Compiling with Angular sources in Ivy partial compilation mode.
✖ Generating FESM2020
Optional chaining cannot appear in left-hand side (Note that you need plugins to import files that are not JavaScript)
Error: Optional chaining cannot appear in left-hand side (Note that you need plugins to import files that are not JavaScript)
at error (/Users/omar/Sites/met-libs-nx/node_modules/ng-packagr/node_modules/rollup/dist/shared/rollup.js:159:30)
Screen Shot 2022-02-28 at 5 58 56 PM

It looks like @rollup@2.68.0 (/ng-packagr/node_modules/rollup/) throws this error.

There is a lot of chatter about this bug on rollup. but i have not found a solution. rollup/rollup#3582

I tried all the suggestions with rollup and updating it within my project but no luck.

Version Information


Angular CLI: 13.1.3
Node: 14.16.0
Package Manager: npm 6.14.11
OS: darwin x64

Angular: 13.1.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, material, platform-browser
... platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1301.3
@angular-devkit/build-angular   13.1.3
@angular-devkit/core            13.2.5
@angular-devkit/schematics      13.2.5
@angular/cli                    13.1.3
@angular/fire                   7.2.1
@schematics/angular             13.2.5
ng-packagr                      13.1.3
rxjs                            6.6.7
typescript                      4.5.4

Please include all version numbers that might be relevant, e.g. third-party libraries

@ohabash
Copy link
Author

ohabash commented Mar 1, 2022

Just adding context. I asked the rollup community about the same problem and they mentioned an Error.loc or Error.frame file with more error context? I wonder if there are steps I can take to capture that output?

I am working on a reproduction of the issue.

A direct solution would be nice however I am more than happy to read any debugging advice also. This error has be exhausting. Thank you!

rollup/rollup#4420

@alan-agius4
Copy link
Member

Printing the fileInfo on error https://github.com/rollup/rollup/blob/51cab92373bcf8c844a8de2a6765869f7eb05a5d/src/Module.ts#L836 should give should be enough to determine which file is causing the problem.

@alan-agius4
Copy link
Member

alan-agius4 commented Mar 2, 2022

I believe the problem is caused by the below and since you are using casting you are also bypassing Typescript error reporting.

(this.schema?.fields as Field[])[e.previousContainer.data.index] = e.container.data.item;
(this.schema?.fields as Field[])[e.container.data.index] = e.previousContainer.data.item;

@ohabash
Copy link
Author

ohabash commented Mar 2, 2022

We included the comment described below. That told us the file that was being parsed before the throw. if I wasn't so happy that this is finally solved Id say something like... Why wasn't the error source printed in the first place!?! 😓

node_modules/ng-packagr/node_modules/rollup/dist/shared/rollup.js

was

if (!ast) {
   ast = this.tryParse();
}

With comment

if (!ast) {
    console.log('rollup parsing ===> originalSourcemap.sources :', originalSourcemap.sources);
   ast = this.tryParse();
}

Code that caused the error

this.schema?.fields[e.container.data.index] = e.previousContainer.data.item;

@github-actions
Copy link

github-actions bot commented Apr 3, 2022

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

This action has been performed automatically by a bot.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants