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

Cannot read property 'defaultView' of undefined error with angular 11.0.0-rc.0 #2572

Closed
xmlking opened this issue Oct 25, 2020 · 10 comments
Closed

Comments

@xmlking
Copy link

xmlking commented Oct 25, 2020

after upgrading to angular 11.0.0-rc.0 , getting the following error

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'defaultView' of undefined
TypeError: Cannot read property 'defaultView' of undefined
at NbViewportRulerAdapter._getWindow (vendor.js:137233)
at vendor.js:137148
at ZoneDelegate.invoke (zone-evergreen.js:368)
at Zone.run (zone-evergreen.js:130)
at NgZone.runOutsideAngular (vendor.js:94965)
at new ViewportRuler (vendor.js:137146)
at new NbViewportRulerAdapter (vendor.js:36207)
at Object.NbViewportRulerAdapter_Factory [as factory] (vendor.js:36234)
at R3Injector.hydrate (vendor.js:78845)
at R3Injector.get (vendor.js:78667)
at resolvePromise (zone-evergreen.js:1209)
at resolvePromise (zone-evergreen.js:1163)
at zone-evergreen.js:1275
at ZoneDelegate.invokeTask (zone-evergreen.js:402)
at Object.onInvokeTask (vendor.js:95026)
at ZoneDelegate.invokeTask (zone-evergreen.js:401)
at Zone.runTask (zone-evergreen.js:174)
at drainMicroTaskQueue (zone-evergreen.js:578)
defaultErrorLogger @ vendor.js:71754

@mruknowme
Copy link

The same issue after updating to stable Angular 11

@EvgenyProkopovich
Copy link

The same issue. Angular 11.0.0. Nebular 6.2.1

@nathane2019
Copy link

I had a similar issue, I am running angular 10 and in order for me to resolve the issue I checked the peer dependencies of the nebular module and verified that it aligns to the cdk version in your package.json. I had to downgrade my version to 10.2.1. For some reason it installed cdk 11

@Sliverb
Copy link

Sliverb commented Nov 20, 2020

Another solution if you want to stay with angular 11 is to patch the nebula package till its updated. The issue is the new ViewportRuler requires the document to be passed into its constructor, so you can have NbViewportRulerAdapter pass this in its super call

You will need patch-package and run it postinstall

Files to patch are

@nebular/theme/bundles/theme.umd.js
@nebular/theme/esm2015/components/cdk/adapter/viewport-ruler-adapter.js
@nebular/theme/fesm2015/index.js

Here is the resulting patched file

diff --git a/node_modules/@nebular/theme/bundles/theme.umd.js b/node_modules/@nebular/theme/bundles/theme.umd.js
index e83ea41..3d2e858 100644
--- a/node_modules/@nebular/theme/bundles/theme.umd.js
+++ b/node_modules/@nebular/theme/bundles/theme.umd.js
@@ -1057,7 +1057,7 @@ var NbOverlayContainerAdapter = /** @class */ (function (_super) {
 var NbViewportRulerAdapter = /** @class */ (function (_super) {
     tslib.__extends(NbViewportRulerAdapter, _super);
     function NbViewportRulerAdapter(platform, ngZone, ruler, scroll) {
-        var _this = _super.call(this, platform, ngZone) || this;
+        var _this = _super.call(this, platform, ngZone, document) || this;
         _this.ruler = ruler;
         _this.scroll = scroll;
         return _this;
diff --git a/node_modules/@nebular/theme/esm2015/components/cdk/adapter/viewport-ruler-adapter.js b/node_modules/@nebular/theme/esm2015/components/cdk/adapter/viewport-ruler-adapter.js
index 2485b14..58884ad 100644
--- a/node_modules/@nebular/theme/esm2015/components/cdk/adapter/viewport-ruler-adapter.js
+++ b/node_modules/@nebular/theme/esm2015/components/cdk/adapter/viewport-ruler-adapter.js
@@ -6,7 +6,7 @@ import { NbLayoutRulerService } from '../../../services/ruler.service';
 import { NbLayoutScrollService } from '../../../services/scroll.service';
 export class NbViewportRulerAdapter extends ViewportRuler {
     constructor(platform, ngZone, ruler, scroll) {
-        super(platform, ngZone);
+        super(platform, ngZone, document);
         this.ruler = ruler;
         this.scroll = scroll;
     }
diff --git a/node_modules/@nebular/theme/fesm2015/index.js b/node_modules/@nebular/theme/fesm2015/index.js
index 289ff0a..c34d9a2 100644
--- a/node_modules/@nebular/theme/fesm2015/index.js
+++ b/node_modules/@nebular/theme/fesm2015/index.js
@@ -959,7 +959,7 @@ NbOverlayContainerAdapter.decorators = [
 
 class NbViewportRulerAdapter extends ViewportRuler {
     constructor(platform, ngZone, ruler, scroll) {
-        super(platform, ngZone);
+        super(platform, ngZone, document);
         this.ruler = ruler;
         this.scroll = scroll;
     }

@mruknowme
Copy link

mruknowme commented Nov 21, 2020

Thank you @Sliverb, it worked. What I did:

  1. npm i patch-package
  2. Make changes as @Sliverb described above
  3. I was getting errors as described here error: Error: spawnSync git ENOBUFS ds300/patch-package#166 (comment), so I made changes as described in comment 166
  4. npx patch-package patch-package
  5. npx patch-package @nebular/theme
  6. Add patch-package to postinstall in packages.json
  7. rm -rf ./node_modules (didn't work until I deleted and reinstalled)
  8. npm i

Should be good to go.

Also, as a side note, it was still failing for me on node 15.2.1, npm 7.0.3, with nvm downgraded to latest node 14.x.x npm 6.x.x and it worked

@almarro1
Copy link

I submitted a pull request to fix this problem following the concept in #2572 (comment)
Hope admins approve the request soon

@arpansac
Copy link

arpansac commented Jan 6, 2021

+1 Setup a project yesterday and today it's stopped working

@petrot
Copy link

petrot commented Jan 15, 2021

Any info about the fixing PR?

@zackstam
Copy link

I just changed version cdk to "@angular/cdk": "^10.2.7", it works

@yggg
Copy link
Contributor

yggg commented Oct 9, 2021

Fixed in the 7th version.

@yggg yggg closed this as completed Oct 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants