Skip to content

ng update to Angular 8 fails: Cannot read property 'module' of undefined #30356

Closed

Description

@darkbasic

🐞 Bug report

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [x] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Description

$ ng update @angular/core --from 7 --to 8 --migrate-only
            ------ Static Query migration ------
            In preparation for Ivy, developers can now explicitly specify the
            timing of their queries. Read more about this here:
            https://github.com/angular/angular/pull/28810
            
            There are two available migration strategies that can be selected:
              • Template strategy  -  migration tool (short-term gains, rare corrections)
              • Usage strategy  -  best practices (long-term gains, manual corrections)
            For an easy migration, the template strategy is recommended. The usage
            strategy can be used for best practices and a code base that will be more
            flexible to changes going forward.
? What migration strategy do you want to use? Template strategy
            
Cannot read property 'module' of undefined
$ ng update @angular/core --from 7 --to 8 --migrate-only
            ------ Static Query migration ------
            In preparation for Ivy, developers can now explicitly specify the
            timing of their queries. Read more about this here:
            https://github.com/angular/angular/pull/28810
            
            There are two available migration strategies that can be selected:
              • Template strategy  -  migration tool (short-term gains, rare corrections)
              • Usage strategy  -  best practices (long-term gains, manual corrections)
            For an easy migration, the template strategy is recommended. The usage
            strategy can be used for best practices and a code base that will be more
            flexible to changes going forward.
? What migration strategy do you want to use? Usage strategy
            
Cannot read property 'kind' of undefined

🔥 Exception or Error


Template strategy:
Cannot read property 'module' of undefined

Usage strategy:
Cannot read property 'kind' of undefined

🌍 Your Environment


Angular CLI: 8.0.0-rc.2
Node: 10.15.3
OS: linux x64
Angular: 8.0.0-rc.2
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router

Package                                    Version
--------------------------------------------------------------------
@angular-devkit/architect                  0.800.0-rc.2
@angular-devkit/build-angular              0.800.0-rc.2
@angular-devkit/build-ng-packagr           0.800.0-rc.2
@angular-devkit/build-optimizer            0.800.0-rc.2
@angular-devkit/build-webpack              0.800.0-rc.2
@angular-devkit/core                       8.0.0-rc.2
@angular-devkit/schematics                 8.0.0-rc.2
@angular/cdk                               8.0.0-rc.0
@angular/flex-layout                       7.0.0-beta.24
@angular/http                              8.0.0-beta.10+1.sha-a28b3e3
@angular/material                          8.0.0-rc.0
@ngtools/json-schema                       1.1.0
@ngtools/webpack                           8.0.0-rc.2
@nguniversal/express-engine                v7.0.2
@nguniversal/module-map-ngfactory-loader   v7.0.2
@schematics/angular                        8.0.0-rc.2
@schematics/update                         0.800.0-rc.2
ng-packagr                                 5.1.0
rxjs                                       6.5.1
typescript                                 3.4.5
webpack                                    4.30.0

Note: flex-layout still doesn't support Angular 8: angular/flex-layout#1029
Maybe it is related to it?

I tried to install a local copy of @angular/cli in order to debug it, but I didn't succeed.
Despite yarn linking all of the following

@angular-devkit/core
@angular-devkit/schematics
@schematics/angular
@schematics/update
@angular-devkit/architect
@angular-devkit/build-optimizer
@angular-devkit/build-webpack
@ngtools/webpack
@angular-devkit/build-angular
@angular-devkit/build-ng-packagr

I still get:

$ ./node_modules/.bin/ng --version            
internal/modules/cjs/loader.js:584
    throw err;
    ^

Error: Cannot find module '../lib/init'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/home/niko/WebstormProjects/deps/angular-cli/packages/angular/cli/bin/ng:25:1)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)

Activity

  1. devversion commented on May 5, 2019

    @devversion
    Member

    Thanks for the issue @darkbasic. The template strategy actually uses the @angular/compiler internally and the exception seems to come from there. Can you confirm that serving the application with --aot actually works in your case? (after the update; also yes- it's possible that flex-layout is the culprit)

    The error for the usage strategy seems definitely like a bug. It's difficult to figure out where it comes from due to the error message not containing a stack trace, but I'll try to find it. Thanks!

    If you have a chance, it would be awesome if you could:

    1. Open file: node_modules/@angular/core/schematics/migrations/static-queries/strategies/usage_strategy/declaration_usage_visitor.js.
    2. Go to the declaration of _updateContext and add a safety check for argumentNode (ensure it's not undefined).

    Finally, please rerun the usage strategy migration. If that fixed the issue, that would be great to know 😄

  2. darkbasic commented on May 5, 2019

    @darkbasic
    Author

    Can you confirm that serving the application with --aot actually works in your case?

    Production build (aot, minification, etc.) works flawlessly.

    _updateContext(callArgs, parameters) {
        parameters.forEach((parameter, index) => {
            console.log("_updateContext()");
            let argumentNode = callArgs[index];
            if (argumentNode !== undefined) {
                if (ts.isIdentifier(argumentNode)) {
                    this.context.set(parameter, this._resolveIdentifier(argumentNode));
                }
                else {
                    this.context.set(parameter, argumentNode);
                }
            } else {
                console.log("!!! argumentNode is undefined !!!");
            }
        });
    }

    For the template strategy nothing changes: I still get Cannot read property 'module' of undefined and _updateContext never gets called.

    On the contrary for the usage strategy it did the trick:

    Details ``` $ ./node_modules/.bin/ng update @angular/core --from 7 --to 8 --migrate-only ------ Static Query migration ------ In preparation for Ivy, developers can now explicitly specify the timing of their queries. Read more about this here: https://github.com//pull/28810
            There are two available migration strategies that can be selected:
              • Template strategy  -  migration tool (short-term gains, rare corrections)
              • Usage strategy  -  best practices (long-term gains, manual corrections)
            For an easy migration, the template strategy is recommended. The usage
            strategy can be used for best practices and a code base that will be more
            flexible to changes going forward.
    

    ? What migration strategy do you want to use? Usage strategy

    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    !!! argumentNode is undefined !!!
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    _updateContext()
    ------------------------------------------------
    UPDATE [...]

    </details>
    
  3. devversion commented on May 5, 2019

    @devversion
    Member

    @darkbasic Thank for helping with this. That confirms that the _updateContext fix I've made in #30269 solves this issue.

    For the template strategy. I was able to reproduce this issue as well, but I'm not sure if it's similar to yours. Can you check if you have any tsconfig file where the angularCompilerOptions are specified with some flatModuleX options? If so, it would be helpful to know where it is stored and if it is referenced in the angular.json file.

    That is all. Thanks for the help! very appreciated 😄

  4. added this to the needsTriage milestone on May 9, 2019
  5. devversion commented on May 10, 2019

    @devversion
    Member

    Fixes landed for the _updateContext and a better messaging when the AOT compiler fails for the template strategy. I'll do some manual testing again, but I'm pretty sure the template strategy failure is caused by having a tsconfig with angularCompilerOptions > flatModuleX options set.

    See: #30269

  6. angular-automatic-lock-bot commented on Sep 15, 2019

    @angular-automatic-lock-bot

    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.

  7. locked and limited conversation to collaborators on Sep 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions