# \[Solved\] TypeError: Cannot read property 'contains' of null

**URL:** <https://forums.bitovi.com/t/solved-typeerror-cannot-read-property-contains-of-null/969>\
**Category:** DoneJS\
**Created:** [September 26, 2018, 1:28am UTC](https://forums.bitovi.com/t/solved-typeerror-cannot-read-property-contains-of-null/969 "2018-09-26T01:28:09Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![leoj3n](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/leoj3n/32/174_2.png) [@leoj3n](https://forums.bitovi.com/u/leoj3n)\
**Post date:** [September 26, 2018, 1:28am UTC](https://forums.bitovi.com/t/solved-typeerror-cannot-read-property-contains-of-null/969/1 "2018-09-26T01:28:09Z")

</div>

I’m having some trouble with SSR in [an application](https://github.com/leoj3n/bitcentivez) I’m trying to use it in.

The error I’m seeing is `TypeError: Cannot read property 'contains' of null`.

It’s like SSR is trying to manipulate a DOM that is not there. I’m using [`done-ssr-middleware`](https://github.com/donejs/done-ssr-middleware) on the server and [`autorender`](https://github.com/donejs/autorender) on the client.

Here’s my issue documenting the full error as seen both locally and on Heroku:

[https://github.com/leoj3n/bitcentivez/issues/1](https://github.com/leoj3n/bitcentivez/issues/1)

Please take note of the dependency versions and such for the client app:

> <https://github.com/leoj3n/bitcentivez/blob/0485f332c78b1c6aea4b15f042b5fb7b65a5a035/client/package.json#L13-L31>

And the server app:

> <https://github.com/leoj3n/bitcentivez/blob/0485f332c78b1c6aea4b15f042b5fb7b65a5a035/server/package.json#L17-L31>

Also note these important client app files:

- [https://github.com/leoj3n/bitcentivez/blob/master/client/app.js](https://github.com/leoj3n/bitcentivez/blob/master/client/app.js)
- [https://github.com/leoj3n/bitcentivez/blob/master/client/index.stache](https://github.com/leoj3n/bitcentivez/blob/master/client/index.stache)

And these server app files:

- [https://github.com/leoj3n/bitcentivez/blob/master/server/index.js](https://github.com/leoj3n/bitcentivez/blob/master/server/index.js)
- [https://github.com/leoj3n/bitcentivez/blob/master/server/app.js](https://github.com/leoj3n/bitcentivez/blob/master/server/app.js)
- [https://github.com/leoj3n/bitcentivez/blob/master/server/middleware/index.js](https://github.com/leoj3n/bitcentivez/blob/master/server/middleware/index.js)
- [https://github.com/leoj3n/bitcentivez/blob/master/server/middleware/ssr.js](https://github.com/leoj3n/bitcentivez/blob/master/server/middleware/ssr.js)

As mentioned in [the issue](https://github.com/leoj3n/bitcentivez/issues/1) linked above, `npm run develop-static` (uses the static middleware) works but `npm run develop-ssr` (uses the ssr middleware) errors as explained.

Hopefully someone familiar with SSR can clone the repo to help me explain what’s going wrong?

Thanks!

---

<div class="post-metadata">

**Author:** ![justinbmeyer](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/justinbmeyer/32/179_2.png) [@justinbmeyer](https://forums.bitovi.com/u/justinbmeyer)\
**Post date:** [September 26, 2018, 2:04am UTC](https://forums.bitovi.com/t/solved-typeerror-cannot-read-property-contains-of-null/969/2 "2018-09-26T02:04:10Z")

</div>

I think @matthewp was just fixing a problem related to contains. He will probably be able to update you tomorrow.

---

<div class="post-metadata">

**Author:** ![matthewp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/matthewp/32/77_2.png) [@matthewp](https://forums.bitovi.com/u/matthewp)\
**Post date:** [September 26, 2018, 11:50am UTC](https://forums.bitovi.com/t/solved-typeerror-cannot-read-property-contains-of-null/969/3 "2018-09-26T11:50:24Z")

</div>

This was fixed in can-view-live yesterday. Update your dependencies and all should be well.

---

<div class="post-metadata">

**Author:** ![leoj3n](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/leoj3n/32/174_2.png) [@leoj3n](https://forums.bitovi.com/u/leoj3n)\
**Post date:** [September 26, 2018, 9:38pm UTC](https://forums.bitovi.com/t/solved-typeerror-cannot-read-property-contains-of-null/969/4 "2018-09-26T21:38:48Z")

</div>

Thanks @matthewp.

I am still getting a `'contains'` error but instead of being in `lib/core.js` it seems to now be in `lib/attrs.js`.

I’ve updated my GitHub issue with a comment showing the full error:

[https://github.com/leoj3n/bitcentivez/issues/1#issuecomment-424877544](https://github.com/leoj3n/bitcentivez/issues/1#issuecomment-424877544)

Is this something you’re actively working on? Anything I should try next?

---

<div class="post-metadata">

**Author:** ![justinbmeyer](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/justinbmeyer/32/179_2.png) [@justinbmeyer](https://forums.bitovi.com/u/justinbmeyer)\
**Post date:** [September 26, 2018, 10:06pm UTC](https://forums.bitovi.com/t/solved-typeerror-cannot-read-property-contains-of-null/969/5 "2018-09-26T22:06:28Z")

</div>

Did you delete your package-lock?

---

<div class="post-metadata">

**Author:** ![leoj3n](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/leoj3n/32/174_2.png) [@leoj3n](https://forums.bitovi.com/u/leoj3n)\
**Post date:** [September 27, 2018, 6:36am UTC](https://forums.bitovi.com/t/solved-typeerror-cannot-read-property-contains-of-null/969/6 "2018-09-27T06:36:16Z")

</div>

Hey @justinbmeyer, thanks for replying.

If you look at the repo, there is an `.npmrc` with `package-lock=false` anywhere there’s a `package.json`. So, to answer the question, there are no `package-lock.json` files.

I even double-checked just now to make 100% sure, and can affirm that there are none in the project.

Also, if you look closer at the [GitHub issue comment](https://github.com/leoj3n/bitcentivez/issues/1#issuecomment-424877544) I linked, you will see I verified the versions of `can-view-live` are at `4.2.2` (not `4.2.1`) even for nested and deduped deps using `npm ls can-view-live`.

---

<div class="post-metadata">

**Author:** ![justinbmeyer](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/justinbmeyer/32/179_2.png) [@justinbmeyer](https://forums.bitovi.com/u/justinbmeyer)\
**Post date:** [September 27, 2018, 7:02pm UTC](https://forums.bitovi.com/t/solved-typeerror-cannot-read-property-contains-of-null/969/7 "2018-09-27T19:02:51Z")

</div>

It looks like it’s using `el.ownerDocument.documentElement.contains(el)`. Any idea why `documentElement` would be null @matthewp ?

---

<div class="post-metadata">

**Author:** ![justinbmeyer](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/justinbmeyer/32/179_2.png) [@justinbmeyer](https://forums.bitovi.com/u/justinbmeyer)\
**Post date:** [September 27, 2018, 7:05pm UTC](https://forums.bitovi.com/t/solved-typeerror-cannot-read-property-contains-of-null/969/8 "2018-09-27T19:05:40Z")

</div>

@leoj3n can you try changing the following at [https://github.com/canjs/can-view-live/blob/master/lib/attrs.js#L102](https://github.com/canjs/can-view-live/blob/master/lib/attrs.js#L102)

```auto
if (!el.ownerDocument.documentElement.contains(el)) {
			teardownHandler();
		}

```

to:

```auto

			var doc = el.ownerDocument;
			var ownerNode = doc.contains ? doc : doc.documentElement;
 			if (!ownerNode.contains(el)) {
				teardownHandler();
			}

```

?

---

<div class="post-metadata">

**Author:** ![matthewp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/matthewp/32/77_2.png) [@matthewp](https://forums.bitovi.com/u/matthewp)\
**Post date:** [September 27, 2018, 7:36pm UTC](https://forums.bitovi.com/t/solved-typeerror-cannot-read-property-contains-of-null/969/9 "2018-09-27T19:36:42Z")

</div>

documentElement gets removed to trigger memory cleanup after the Zone has completed. My can-view-live release should have gotten this. Was there another one? If so you can do the same sort of thing, use document.contains if it exists.

---

<div class="post-metadata">

**Author:** ![leoj3n](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/leoj3n/32/174_2.png) [@leoj3n](https://forums.bitovi.com/u/leoj3n)\
**Post date:** [September 28, 2018, 12:45am UTC](https://forums.bitovi.com/t/solved-typeerror-cannot-read-property-contains-of-null/969/10 "2018-09-28T00:45:58Z")

</div>

Woohoo! That works. Thanks again @justinbmeyer and @matthewp.

I’ve opened a PR with this change, hope this helps:

[https://github.com/canjs/can-view-live/pull/125](https://github.com/canjs/can-view-live/pull/125)

---

<div class="post-metadata">

**Author:** ![justinbmeyer](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.bitovi.com/justinbmeyer/32/179_2.png) [@justinbmeyer](https://forums.bitovi.com/u/justinbmeyer)\
**Post date:** [September 28, 2018, 2:12pm UTC](https://forums.bitovi.com/t/solved-typeerror-cannot-read-property-contains-of-null/969/11 "2018-09-28T14:12:24Z")

</div>

Published fix: [https://github.com/canjs/can-view-live/releases/tag/v4.2.3](https://github.com/canjs/can-view-live/releases/tag/v4.2.3)
