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

bug(cdk): Update Failed : Cannot read property 'length' of null #19779

Closed
filol opened this issue Jun 26, 2020 · 6 comments · Fixed by #19783 or #19934
Closed

bug(cdk): Update Failed : Cannot read property 'length' of null #19779

filol opened this issue Jun 26, 2020 · 6 comments · Fixed by #19783 or #19934
Assignees
Labels
area: cdk/schematics cdk/schematics is *not* a public API area: ng-update Issues related to `ng-update` integration P2 The issue is important to a large percentage of users, with a workaround

Comments

@filol
Copy link

filol commented Jun 26, 2020

Reproduction

I can't share my code because it's a big project, hope the stack will help you
ng update @angular/material --force

Expected Behavior

Working

Actual Behavior

 ** Executing migrations for package '@angular/cdk' **
Cannot read property 'length' of null

Stack trace in log file :

[error] TypeError: Cannot read property 'length' of null
    at Object.computeLineStartsMap (path\node_modules\@angular\cdk\schematics\update-tool\utils\line-mappings.js:39:23)
    at ComponentResourceCollector.resolveExternalStylesheet (path\node_modules\@angular\cdk\schematics\update-tool\component-resource-collector.js:131:47)
    at path\node_modules\@angular\cdk\schematics\update-tool\index.js:97:50
    at Array.forEach (<anonymous>)
    at UpdateProject.migrate (path\node_modules\@angular\cdk\schematics\update-tool\index.js:95:35)
    at runMigrations (path\node_modules\@angular\cdk\schematics\ng-update\devkit-migration-rule.js:128:42)
    at Object.<anonymous> (path\node_modules\@angular\cdk\schematics\ng-update\devkit-migration-rule.js:83:17)
    at Generator.next (<anonymous>)
    at path\node_modules\@angular\cdk\schematics\ng-update\devkit-migration-rule.js:15:71
    at new Promise (<anonymous>)
    at __awaiter (path\node_modules\@angular\cdk\schematics\ng-update\devkit-migration-rule.js:11:12)
    at path\node_modules\@angular\cdk\schematics\ng-update\devkit-migration-rule.js:57:31
    at MergeMapSubscriber.project (path\node_modules\@angular-devkit\schematics\src\rules\call.js:75:24)
    at MergeMapSubscriber._tryNext (path\node_modules\rxjs\internal\operators\mergeMap.js:69:27)
    at MergeMapSubscriber._next (path\node_modules\rxjs\internal\operators\mergeMap.js:59:18)
    at MergeMapSubscriber.Subscriber.next (path\node_modules\rxjs\internal\Subscriber.js:66:18)

Environment

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 10.0.0
Node: 12.4.0
OS: win32 x64

Angular: 10.0.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, language-service, material, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.1000.0
@angular-devkit/build-angular     0.1000.0
@angular-devkit/build-optimizer   0.1000.0
@angular-devkit/build-webpack     0.1000.0
@angular-devkit/core              10.0.0
@angular-devkit/schematics        10.0.0
@angular/flex-layout              10.0.0-beta.32
@ngtools/webpack                  10.0.0
@schematics/angular               9.1.9
@schematics/update                0.1000.0
rxjs                              6.5.5
typescript                        3.9.5
webpack                           4.43.0
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 10
@filol filol added the needs triage This issue needs to be triaged by the team label Jun 26, 2020
@crisbeto crisbeto self-assigned this Jun 27, 2020
@crisbeto crisbeto added area: cdk/schematics cdk/schematics is *not* a public API area: ng-update Issues related to `ng-update` integration has pr P2 The issue is important to a large percentage of users, with a workaround and removed needs triage This issue needs to be triaged by the team labels Jun 27, 2020
crisbeto added a commit to crisbeto/material2 that referenced this issue Jun 27, 2020
In some cases the schematics fail to read a file which results in an error, because we weren't guarding against it properly. We had the correct types in place, but the tsconfig didn't have `strictNullChecks` enabled which prevented the compiler from reporting the errors.

Fixes angular#19779.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jun 27, 2020
In some cases the schematics fail to read a file which results in an error, because we weren't guarding against it properly. We had the correct types in place, but the tsconfig didn't have `strictNullChecks` enabled which prevented the compiler from reporting the errors.

Fixes angular#19779.
@devversion devversion added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed P2 The issue is important to a large percentage of users, with a workaround labels Jun 29, 2020
@devversion
Copy link
Member

@filol Thanks for this issue! Do you know if you have any files in your project that are not readable? or in better terms which might have permission issues? We have a fix for this in progress, but we'd like to understand how this issue surfaces on your end.

If possible, it would be great to have the requested information above, and potentially when you get a chance, it might be helpful if you manually modify the resolveExternalStylesheet function and log/debug the file path. That would be awesome.

If that's not possible (due to the incremental nature of ng update), let me know. Not a big deal. Thanks!

@filol
Copy link
Author

filol commented Jun 29, 2020

@devversion @crisbeto I checked I have all the rights, I even closed my IDE, launched the console in administrator mode and it is exactly the same error.

I'm not sure I understood the "requested information above" of your message.

I have manually log the path, the error is throw on the first path :

Repository is not clean. Update changes will be mixed with pre-existing changes.
Using package manager: 'yarn'
Collecting installed dependencies...
Found 59 dependencies.
** Executing migrations of package '@angular/material' **

> Updates Angular Material to v10
Path : components/business/appels-d-offres/appels-d-offres.component.scss
× Migration failed: Cannot read property 'length' of null
  See "C:\Users\FRANOI~1\AppData\Local\Temp\ng-SlLOJo\angular-errors.log" for further details.

If you want i can provide you this file but it's really basic

@devversion
Copy link
Member

@filol Thanks! yeah, with information above I actually just referred to the "permission issues". Thanks for checking that.

Does your project have the file components/business/appels-d-offres/appels-d-offres.component.scss? It would be interesting to see if the components folder is directly at same level with the angular.json file. Can you please check that? That would be all.

@filol
Copy link
Author

filol commented Jun 29, 2020

@devversion Yes, he exist and no they are not on the same level. Here is the return of the tree command without the files not relevant

├──  .prettierignore
├── Dockerfile
├── README.md
├── angular.json
├── buildspec-pr.yml
├── buildspec-staging.yml
├── buildspec.yml
├── e2e
│   ├── protractor.conf.js
│   ├── src
│   │   ├── app.e2e-spec.ts
│   │   └── app.po.ts
│   └── tsconfig.json
├── git.version.ts
├── images
│   └── architecture.png
├── karma.conf.js
├── package-lock.json
├── package.json
├── scripts
├── src
│   ├── app
│   │   ├── app-routing.module.ts
│   │   ├── app.component.html
│   │   ├── app.component.scss
│   │   ├── app.component.ts
│   │   ├── app.module.ts
│   │   ├── components
│   │   │   ├── business
│   │   │   │   ├── appels-d-offres
│   │   │   │   │   ├── appels-d-offres-routing.module.ts
│   │   │   │   │   ├── appels-d-offres.component.html
│   │   │   │   │   ├── appels-d-offres.component.scss
│   │   │   │   │   ├── appels-d-offres.component.ts
│   │   │   │   │   └── appels-d-offres.module.ts
│   │   │   │   ├── business-routing.module.ts
│   │   │   │   ├── business.module.ts
│   │   ├── directives
│   │   ├── errors
│   │   ├── guards
│   │   ├── interceptors
│   │   ├── interfaces
│   │   ├── models
│   │   ├── pipes
│   │   ├── services
│   │   └── utils
│   ├── assets
│   ├── environments
│   │   ├── environment.prod.ts
│   │   ├── environment.staging.ts
│   │   ├── environment.ts
│   │   └── versions.ts
│   ├── favicon.ico
│   ├── index.html
│   ├── main.ts
│   ├── polyfills.ts
│   ├── styles
│   ├── styles.scss
│   └── test.ts
├── tree.txt
├── tsconfig.app.json
├── tsconfig.base.json
├── tsconfig.json
├── tsconfig.spec.json
├── tslint.json
```

@devversion devversion self-assigned this Jun 29, 2020
jelbourn pushed a commit that referenced this issue Jun 30, 2020
In some cases the schematics fail to read a file which results in an error, because we weren't guarding against it properly. We had the correct types in place, but the tsconfig didn't have `strictNullChecks` enabled which prevented the compiler from reporting the errors.

Fixes #19779.
jelbourn pushed a commit that referenced this issue Jun 30, 2020
In some cases the schematics fail to read a file which results in an error, because we weren't guarding against it properly. We had the correct types in place, but the tsconfig didn't have `strictNullChecks` enabled which prevented the compiler from reporting the errors.

Fixes #19779.
@devversion devversion reopened this Jul 1, 2020
@devversion
Copy link
Member

Reopening this as the error has been fixed, but it doesn't fix that actual stylesheets are not migrated. It looks like ng update has been run from within a different folder somehow. My understanding though was that the Angular CLI no longer supports this / that the devkit virtual tree always starts from the workspace root.

@devversion devversion removed the has pr label Jul 2, 2020
devversion added a commit to devversion/material2 that referenced this issue Jul 9, 2020
In some situations, developers will run `ng update` from a sub directory
of the project. This currently results in a noop migration as file
system paths were computed incorrectly. This is because ng-update
always assumed that the CWD is the workspace root in the real file
system. This is not the case and therefore threw off path resolution.

We can fix this by determining the workspace file system path from
the virtual file system host tree's. This is not ideal, but best
solution for now until we can parse/resolve TypeScript projects
purely from within the virtual file system. This is currently
not easy to implement and requires helpers from TS which are
not exposed yet. See:
microsoft/TypeScript#13793.

This is tracked with: COMP-387.

Fixes angular#19779.
@devversion devversion added has pr P2 The issue is important to a large percentage of users, with a workaround and removed P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Jul 9, 2020
devversion added a commit to devversion/material2 that referenced this issue Jul 10, 2020
In some situations, developers will run `ng update` from a sub directory
of the project. This currently results in a noop migration as file
system paths were computed incorrectly. This is because ng-update
always assumed that the CWD is the workspace root in the real file
system. This is not the case and therefore threw off path resolution.

We fix this by fully relying on the virtual file system now. Previously
we mixed virtual and real file system as TypeScript relied on the
real file system for parsing configuration, matching and reading files.

This commit adds a new compiler host for config parsing and program
creation that works fully with a virtual file system. This is something
we had planned a long time ago as schematics should never deal with
the real file system. We can re-use this logic in other repositories
too (such as Angular framework, potentially the CLI, and universal
schematics). Ideally we will share this as part of better tooling for
migrations.

Fixes angular#19779.
devversion added a commit to devversion/material2 that referenced this issue Jul 10, 2020
In some situations, developers will run `ng update` from a sub directory
of the project. This currently results in a noop migration as file
system paths were computed incorrectly. This is because ng-update
always assumed that the CWD is the workspace root in the real file
system. This is not the case and therefore threw off path resolution.

We fix this by fully relying on the virtual file system now. Previously
we mixed virtual and real file system as TypeScript relied on the
real file system for parsing configuration, matching and reading files.

This commit adds a new compiler host for config parsing and program
creation that works fully with a virtual file system. This is something
we had planned a long time ago as schematics should never deal with
the real file system. We can re-use this logic in other repositories
too (such as Angular framework, potentially the CLI, and universal
schematics). Ideally we will share this as part of better tooling for
migrations.

Fixes angular#19779.
devversion added a commit to devversion/material2 that referenced this issue Jul 10, 2020
In some situations, developers will run `ng update` from a sub directory
of the project. This currently results in a noop migration as file
system paths were computed incorrectly. This is because ng-update
always assumed that the CWD is the workspace root in the real file
system. This is not the case and therefore threw off path resolution.

We fix this by fully relying on the virtual file system now. Previously
we mixed virtual and real file system as TypeScript relied on the
real file system for parsing configuration, matching and reading files.

This commit adds a new compiler host for config parsing and program
creation that works fully with a virtual file system. This is something
we had planned a long time ago as schematics should never deal with
the real file system. We can re-use this logic in other repositories
too (such as Angular framework, potentially the CLI, and universal
schematics). Ideally we will share this as part of better tooling for
migrations.

Fixes angular#19779.
devversion added a commit to devversion/material2 that referenced this issue Jul 10, 2020
In some situations, developers will run `ng update` from a sub directory
of the project. This currently results in a noop migration as file
system paths were computed incorrectly. This is because ng-update
always assumed that the CWD is the workspace root in the real file
system. This is not the case and therefore threw off path resolution.

We fix this by fully relying on the virtual file system now. Previously
we mixed virtual and real file system as TypeScript relied on the
real file system for parsing configuration, matching and reading files.

This commit adds a new compiler host for config parsing and program
creation that works fully with a virtual file system. This is something
we had planned a long time ago as schematics should never deal with
the real file system. We can re-use this logic in other repositories
too (such as Angular framework, potentially the CLI, and universal
schematics). Ideally we will share this as part of better tooling for
migrations.

Fixes angular#19779.
devversion added a commit to devversion/material2 that referenced this issue Jul 10, 2020
In some situations, developers will run `ng update` from a sub directory
of the project. This currently results in a noop migration as file
system paths were computed incorrectly. This is because ng-update
always assumed that the CWD is the workspace root in the real file
system. This is not the case and therefore threw off path resolution.

We fix this by fully relying on the virtual file system now. Previously
we mixed virtual and real file system as TypeScript relied on the
real file system for parsing configuration, matching and reading files.

This commit adds a new compiler host for config parsing and program
creation that works fully with a virtual file system. This is something
we had planned a long time ago as schematics should never deal with
the real file system. We can re-use this logic in other repositories
too (such as Angular framework, potentially the CLI, and universal
schematics). Ideally we will share this as part of better tooling for
migrations.

Fixes angular#19779.
devversion added a commit to devversion/material2 that referenced this issue Jul 10, 2020
In some situations, developers will run `ng update` from a sub directory
of the project. This currently results in a noop migration as file
system paths were computed incorrectly. This is because ng-update
always assumed that the CWD is the workspace root in the real file
system. This is not the case and therefore threw off path resolution.

We fix this by fully relying on the virtual file system now. Previously
we mixed virtual and real file system as TypeScript relied on the
real file system for parsing configuration, matching and reading files.

This commit adds a new compiler host for config parsing and program
creation that works fully with a virtual file system. This is something
we had planned a long time ago as schematics should never deal with
the real file system. We can re-use this logic in other repositories
too (such as Angular framework, potentially the CLI, and universal
schematics). Ideally we will share this as part of better tooling for
migrations.

Fixes angular#19779.
devversion added a commit to devversion/material2 that referenced this issue Jul 10, 2020
In some situations, developers will run `ng update` from a sub directory
of the project. This currently results in a noop migration as file
system paths were computed incorrectly. This is because ng-update
always assumed that the CWD is the workspace root in the real file
system. This is not the case and therefore threw off path resolution.

We fix this by fully relying on the virtual file system now. Previously
we mixed virtual and real file system as TypeScript relied on the
real file system for parsing configuration, matching and reading files.

This commit adds a new compiler host for config parsing and program
creation that works fully with a virtual file system. This is something
we had planned a long time ago as schematics should never deal with
the real file system. We can re-use this logic in other repositories
too (such as Angular framework, potentially the CLI, and universal
schematics). Ideally we will share this as part of better tooling for
migrations.

Fixes angular#19779.
devversion added a commit to devversion/material2 that referenced this issue Jul 10, 2020
In some situations, developers will run `ng update` from a sub directory
of the project. This currently results in a noop migration as file
system paths were computed incorrectly. This is because ng-update
always assumed that the CWD is the workspace root in the real file
system. This is not the case and therefore threw off path resolution.

We fix this by fully relying on the virtual file system now. Previously
we mixed virtual and real file system as TypeScript relied on the
real file system for parsing configuration, matching and reading files.

This commit adds a new compiler host for config parsing and program
creation that works fully with a virtual file system. This is something
we had planned a long time ago as schematics should never deal with
the real file system. We can re-use this logic in other repositories
too (such as Angular framework, potentially the CLI, and universal
schematics). Ideally we will share this as part of better tooling for
migrations.

Fixes angular#19779.
devversion added a commit to devversion/material2 that referenced this issue Jul 10, 2020
In some situations, developers will run `ng update` from a sub directory
of the project. This currently results in a noop migration as file
system paths were computed incorrectly. This is because ng-update
always assumed that the CWD is the workspace root in the real file
system. This is not the case and therefore threw off path resolution.

We fix this by fully relying on the virtual file system now. Previously
we mixed virtual and real file system as TypeScript relied on the
real file system for parsing configuration, matching and reading files.

This commit adds a new compiler host for config parsing and program
creation that works fully with a virtual file system. This is something
we had planned a long time ago as schematics should never deal with
the real file system. We can re-use this logic in other repositories
too (such as Angular framework, potentially the CLI, and universal
schematics). Ideally we will share this as part of better tooling for
migrations.

Fixes angular#19779.
mmalerba pushed a commit that referenced this issue Jul 11, 2020
In some situations, developers will run `ng update` from a sub directory
of the project. This currently results in a noop migration as file
system paths were computed incorrectly. This is because ng-update
always assumed that the CWD is the workspace root in the real file
system. This is not the case and therefore threw off path resolution.

We fix this by fully relying on the virtual file system now. Previously
we mixed virtual and real file system as TypeScript relied on the
real file system for parsing configuration, matching and reading files.

This commit adds a new compiler host for config parsing and program
creation that works fully with a virtual file system. This is something
we had planned a long time ago as schematics should never deal with
the real file system. We can re-use this logic in other repositories
too (such as Angular framework, potentially the CLI, and universal
schematics). Ideally we will share this as part of better tooling for
migrations.

Fixes #19779.
mmalerba pushed a commit that referenced this issue Jul 11, 2020
In some situations, developers will run `ng update` from a sub directory
of the project. This currently results in a noop migration as file
system paths were computed incorrectly. This is because ng-update
always assumed that the CWD is the workspace root in the real file
system. This is not the case and therefore threw off path resolution.

We fix this by fully relying on the virtual file system now. Previously
we mixed virtual and real file system as TypeScript relied on the
real file system for parsing configuration, matching and reading files.

This commit adds a new compiler host for config parsing and program
creation that works fully with a virtual file system. This is something
we had planned a long time ago as schematics should never deal with
the real file system. We can re-use this logic in other repositories
too (such as Angular framework, potentially the CLI, and universal
schematics). Ideally we will share this as part of better tooling for
migrations.

Fixes #19779.
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: cdk/schematics cdk/schematics is *not* a public API area: ng-update Issues related to `ng-update` integration P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
3 participants