Angular-cli: AoT ERROR in Cannot read property 'codeGen' of undefined

Created on 21 Dec 2016  路  6Comments  路  Source: angular/angular-cli

OS?

OSX El Capitan, OSX Sierra, Amazon Linux on EC2

Versions.

beta.22 / angular 2.2.3

Repro steps.

I have a branch cut from a few weeks ago on the above versions.
Several days ago, ng build --aot=true --target=production works fine.
Yesterday, same command fails (log below)

Keep in mind that this is via a build server on Jenkins, which checks out a clean copy every time. To replicate, I did a clean checkout of my repo in another directory, switch to the cut branch that hasn't been modified since our last sprint, and the same issue appears.

I was able to build fine on my local workspace repo, but once I deleted my cached node_module directory and re-installed all dependencies, I get the same error below.

The log given by the failure.

Hash: 298b4d5b0927ce483a6d Time: 18425ms chunk {0} scripts.2ec7b6c32f2cecb6ef43.bundle.js, scripts.2ec7b6c32f2cecb6ef43.bundle.map (scripts) 112 kB {4} [initial] [rendered] chunk {1} main.0ffb0f0b246299e375b6.bundle.js, main.0ffb0f0b246299e375b6.bundle.map (main) 2.02 kB {3} [initial] [rendered] chunk {2} styles.b2328beb0372c051d06d.bundle.js, styles.fc27ae193c6cf276eb76015a2f77056b.bundle.css, styles.b2328beb0372c051d06d.bundle.map, styles.b2328beb0372c051d06d.bundle.map (styles) 69 bytes {4} [initial] [rendered] chunk {3} vendor.0c6af147dfcf8a75bb37.bundle.js, vendor.0c6af147dfcf8a75bb37.bundle.map (vendor) 855 kB [initial] [rendered] chunk {4} inline.d41d8cd98f00b204e980.bundle.js, inline.d41d8cd98f00b204e980.bundle.map (inline) 0 bytes [entry] [rendered]

ERROR in Cannot read property 'codeGen' of undefined

ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/Users/aaron/repos/my-clean-checkout/src' @ ./src/main.ts 4:0-74 @ multi main

ERROR in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js Module not found: Error: Can't resolve '/Users/aaron/repos/my-clean-checkout/src/$$_gendir' in '/Users/aaron/repos/my-clean-checkout/node_modules/@angular/core/src/linker' @ ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js 46:15-36 58:15-102 @ ./~/@angular/core/src/linker.js @ ./~/@angular/core/src/core.js @ ./~/@angular/core/index.js @ ./src/main.ts @ multi main

Mention any other details that might be useful.

I suspect some breaking bug might have been published to beta.22, angular 2.2.3, or one of its dependencies. NPM is fetching the same version from the public repo as before, but getting a bad version now.

Upgrading to beta.24 / angular 2.3.0+ may not be a feasible solution since I use a few libraries that hasn't been exported to be AoT compatible for 2.3.0+, but instead still works for 2.2.3. If I were to upgrade, I get the error reported at #3674

UPDATE the internal dependency in question appears to be "@ngtools/webpack". Perhaps the solution is to pin beta.22's ngtools/webpack to version 1.1.9, instead of specifying the latest minor/patch version, which resolves to 1.2.1 according to npmjs

Most helpful comment

@bmbrown10 I figured out a workaround from another user in the other issue I referenced above:

Instead of downgrading to beta.21, pin cli's internal dependencies by adding "@ngtools/webpack": "1.1.9" to your package.json. Once I did that, the error went away and build/serves aot fine.

I will update the original issue to suggest such a fix as well.

All 6 comments

looks like packages/@ngtools/webpack/src/plugin.ts from this commit is causing the problem becauase of the change to the appending onto the path.
https://github.com/angular/angular-cli/commit/db4e0242c482be46b47b78d54c9b4c33bbf57591

I'm reverting back to version [email protected] to see if that fixes the problem.

@bmbrown10 I figured out a workaround from another user in the other issue I referenced above:

Instead of downgrading to beta.21, pin cli's internal dependencies by adding "@ngtools/webpack": "1.1.9" to your package.json. Once I did that, the error went away and build/serves aot fine.

I will update the original issue to suggest such a fix as well.

@aaronleeucla it works for me also. But i installed @ngtools/webpack using npm install @ngtools/[email protected] and it worked

I think we didn't pin @ngtools/webpack on those releases and thus newer ones broke it. The solution is to either pin it on your project, or update.

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

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hareeshav picture hareeshav  路  3Comments

rajjejosefsson picture rajjejosefsson  路  3Comments

gotschmarcel picture gotschmarcel  路  3Comments

purushottamjha picture purushottamjha  路  3Comments

rwillmer picture rwillmer  路  3Comments