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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

NGCC fails if there is a "main" in a non-angular package that is has multiple UMD/CommonJS declarations in a .js file #33697

Closed
aaronmanela opened this issue Nov 8, 2019 · 7 comments

Comments

@aaronmanela
Copy link

@aaronmanela aaronmanela commented Nov 8, 2019

馃悶 bug report

Affected Package

The issue is caused by package @angular/compiler@9.0.0-rc.1

Is this a regression?

No

Description

when trying to run the prescribed code for a universal build in testing as mentioned in the docs:


"postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points && ngcc --properties main --create-ivy-entry-points"

in a project that has an angular dependency that in turn depends on a non-angular package that has a "main" defined that is not a umd formatted js

such as
"@angular-skyhook/core":"1.3.3"
"@angular-skyhook/multi-backend":"1.3.3"

I get the error below

馃敩 Minimal Reproduction

download https://stackblitz.com/edit/angular-issue-repro2-6nyjrs

or add the above two dependencies to a fresh angular 9 rc 1 project, and add the following to scripts in your package.json:


"scripts": {
    "postinstall-ivy": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points",
    "postinstall-ivy-umd": "ngcc --properties main --create-ivy-entry-points",
    "postinstall": "npm run postinstall-ivy && npm run postinstall-ivy-umd"
}

now at a command line run


npm i

馃敟 Exception or Error


Expected UMD module file (/node_modules/dnd-multi-backend/lib/index.js) to contain exactly one statement, but found [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object].
    at UmdReflectionHost.getUmdModule (   \node_modules\@angular\compiler-cli\ngcc\src\host\umd_host.js:55:27)
 at UmdReflectionHost.getModuleStatements (  \node_modules\@angular\compiler-cli\ngcc\src\host\umd_host.js:107:34)
    at UmdReflectionHost.computeExportsOfUmdModule ( \node_modules\@angular\compiler-cli\ngcc\src\host\umd_host.js:113:41)
    at UmdReflectionHost.getUmdExports ( \node_modules\@angular\compiler-cli\ngcc\src\host\umd_host.js:94:42)
    at UmdReflectionHost.getExportsOfModule (\node_modules\@angular\compiler-cli\ngcc\src\host\umd_host.js:47:83)
    at UmdReflectionHost.Esm2015ReflectionHost.getDeclarationOfExpression (\node_modules\@angular\compiler-cli\ngcc\src\host\esm2015_host.js:1449:41)
    at UmdReflectionHost.extractUmdExportDeclaration (\node_modules\@angular\compiler-cli\ngcc\src\host\umd_host.js:125:36)
    at \node_modules\@angular\compiler-cli\ngcc\src\host\umd_host.js:114:95
    at Array.map ()
    at UmdReflectionHost.computeExportsOfUmdModule (\node_modules\@angular\compiler-cli\ngcc\src\host\umd_host.js:114:55)
    at ClusterMaster.onWorkerMessage (\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:158:27)
    at \node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:46:95
    at ClusterMaster. (\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:238:57)
    at step (\node_modules\tslib\tslib.js:136:27)
    at Object.next (\node_modules\tslib\tslib.js:117:57)
    at \node_modules\tslib\tslib.js:110:75
    at new Promise ()
    at Object.__awaiter (\node_modules\tslib\tslib.js:106:16)
    at EventEmitter. (\node_modules\@angular\compiler-cli\ngcc\src\execution\cluster\master.js:232:32)
    at EventEmitter.emit (events.js:198:13)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ng9test@0.0.0 postinstall-ivy-umd: `ngcc --properties main --create-ivy-entry-points`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ng9test@0.0.0 postinstall-ivy-umd script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

馃實 Your Environment

Angular Version: 9.0.0-rc.1

Anything else relevant?
This seems to be an issue where the UmdReflectionHost.getUmdModule(sourceFile: ts.sourceFile):UmdModule:null is throwing an error because it is assuming any dependency is an angular dependency. There should be some way of figuring out if the package is in APF and throwing it out if it is not. For instance a simple check to see if there is a dependency or devDependency or peerDependency on "@angular/core" package should be enough to add it to the ignore list. in fact it should probably be smart enough to know if a package uses renderer or renderer2/ViewEngine or render3/Ivy or none of them and error on renderer and skip Ivy and non-angular packages.

@ngbot ngbot bot added this to the needsTriage milestone Nov 8, 2019
@aaronmanela aaronmanela changed the title NGCC fails if there is a "main" in a non-angular package that is not UMD NGCC fails if there is a "main" in a non-angular package that is has multiple UMD declarations in a .js file Nov 11, 2019
@aaronmanela aaronmanela changed the title NGCC fails if there is a "main" in a non-angular package that is has multiple UMD declarations in a .js file NGCC fails if there is a "main" in a non-angular package that is has multiple UMD/CommonJS declarations in a .js file Nov 11, 2019
@aaronmanela

This comment has been minimized.

Copy link
Author

@aaronmanela aaronmanela commented Nov 11, 2019

Actually it looks like the package in question (dnd-multi-backend@3.2.1) is CommonJS with multiple exports and is falling into ngcc's UMD parse code.

@aaronmanela

This comment has been minimized.

Copy link
Author

@aaronmanela aaronmanela commented Nov 11, 2019

But either way it isn't an angular project so I don't understand why it is getting parsed by the compatibility compiler.

@gkalpak gkalpak self-assigned this Nov 11, 2019
@gkalpak

This comment has been minimized.

Copy link
Member

@gkalpak gkalpak commented Nov 11, 2019

I couldn't reproduce the problem based on your instructions, @aaronhoffman 馃槙
Here is what I tried (all commands completed successfully):

npm install --global @angular/cli@9.0.0-rc.1
ng new test-app --defaults
cd test-app
npm install --save @angular-skyhook/core@1.3.3 @angular-skyhook/multi-backend@1.3.3
node_modules/.bin/ngcc --create-ivy-entry-points --first-only --properties es2015 browser module main
node_modules/.bin/ngcc --create-ivy-entry-points --first-only --properties main

Did I miss anything?

@petebacondarwin

This comment has been minimized.

Copy link
Member

@petebacondarwin petebacondarwin commented Nov 11, 2019

The primary indicator for ngcc to decide if a package should be processed is if it has a metadata.json file next to its typings file. dnd-multi-backend does not appear to have such a thing.

@aaronmanela

This comment has been minimized.

Copy link
Author

@aaronmanela aaronmanela commented Nov 13, 2019

I created my repo following the upgrade instructions from angular 8. I will try your way and see what is different.

@aaronmanela

This comment has been minimized.

Copy link
Author

@aaronmanela aaronmanela commented Nov 21, 2019

I haven't been able to repro, will try again in latest RC and maybe we can close this.

@petebacondarwin

This comment has been minimized.

Copy link
Member

@petebacondarwin petebacondarwin commented Nov 21, 2019

Thanks for the update @aaronhoffman - I am going to close this. Please open a new issue with a repro when you get one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.