Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Uncaught ReferenceError: Node is not defined #13442

Closed
MaestroJurko opened this issue Dec 3, 2015 · 30 comments
Closed

Uncaught ReferenceError: Node is not defined #13442

MaestroJurko opened this issue Dec 3, 2015 · 30 comments

Comments

@MaestroJurko
Copy link

angular.js:2789 Uncaught ReferenceError: Node is not defined

Updated from 1.4.7 to 1.4.8

@Narretz
Copy link
Contributor

Narretz commented Dec 3, 2015

Please provide more context information; stacktrace, minimal demo etc.

@Narretz Narretz added this to the Purgatory milestone Dec 3, 2015
@MaestroJurko
Copy link
Author

This happens on specific d3 charts. Will try to create an example, but it works with 1.4.7 version. I see that there were some changes on jqlite. Probably that is the reason.

I am using jquery, did how to use jquery + angularjs changed?

@jlmitch5
Copy link

jlmitch5 commented Dec 3, 2015

No coverage information was collected, exit without writing coverage information
/Users/jmitchell/tower_fork/node_modules/angular/angular.js:2789
var jqLiteContains = Node.prototype.contains || function(arg) {
                     ^

ReferenceError: Node is not defined
    at /Users/jmitchell/tower_fork/node_modules/angular/angular.js:2789:22
    at Object.<anonymous> (/Users/jmitchell/tower_fork/node_modules/angular/angular.js:29016:3)

It's happening after require("angular/angular"); in the traceback

Bumping angular to be specifically 1.4.7 fixes the issue.

@Narretz
Copy link
Contributor

Narretz commented Dec 4, 2015

Ah, I see it's a change that has been made to jqlite which relies on Node. I'm not sure how that's fixable for server use of angular.

@Narretz
Copy link
Contributor

Narretz commented Dec 4, 2015

Actually, how exactly do you use Angular with require? In the browser or on the server?

@jlmitch5
Copy link

jlmitch5 commented Dec 7, 2015

@Narretz I inherited this flow, and I haven't dove too deep/know if its best practice, but we require angular when building the app for testing.

We take several client JS libraries through require, and then set up these to be found on window.

@neha-nsharma
Copy link

I am getting the same exception with the mocha tests after upgrading to angular 1.4.8

var jqLiteContains = Node.prototype.contains || function(arg) {
^
ReferenceError: Node is not defined
at .../angular/angular.js:2789:22

@Narretz
Copy link
Contributor

Narretz commented Dec 10, 2015

@gkalpak ping because you committed the change that causes this. Do you think this is something we should account for?

@gkalpak
Copy link
Member

gkalpak commented Dec 10, 2015

Did I ? Let me take a closer look :)

@gkalpak
Copy link
Member

gkalpak commented Dec 10, 2015

I don't think I was involved with 941c1c3, which introduced this, but I think it is worth solving anyway...
The fix should be pretty simple too.

@Narretz
Copy link
Contributor

Narretz commented Dec 10, 2015

@gkalpak Ah, sorry. But thanks for fixing it ;)

@Narretz
Copy link
Contributor

Narretz commented Dec 16, 2015

@neha-nsharma: can you explain / show your setup? For example, Are you using a module loader or jsdom?

@neha-nsharma
Copy link

I am using jsdom (0.11.1 version); I have the issue running my mocha tests. I was able to make it work by setting Node = window.Node; in the mocha config.

Thank you,
Neha

On Dec 16, 2015, at 1:26 AM, Martin Staffa [email protected] wrote:

@neha-nsharma https://github.com/neha-nsharma: can you explain / show your setup? For example, Are you using a module loader or jsdom?


Reply to this email directly or view it on GitHub #13442 (comment).

@Narretz
Copy link
Contributor

Narretz commented Dec 16, 2015

If you are using jsdom, it's your responsibility to provide the correct context. So I'd say this is not fixable in angular.

@gkalpak
Copy link
Member

gkalpak commented Dec 17, 2015

@neha-nesharma, does it mean that changing Node.prototype.contains to window.Node.prototype.contains in Angular solves the issue ?
That might be a reasonable change.

@neha-nsharma
Copy link

That is correct. This change will work.

Thank you

On Dec 17, 2015, at 7:45 AM, Georgios Kalpakas [email protected] wrote:

@neha-nesharma, does it mean that changing Node.prototype.contains to window.Node.prototype.contains in Angular solves the issue ?
That might be a reasonable change.


Reply to this email directly or view it on GitHub #13442 (comment).

@petebacondarwin
Copy link
Contributor

@mgol is going to look into whether doing this comprehensively is feasible without too much work.

@petebacondarwin petebacondarwin modified the milestones: 1.5.0-rc.1, 1.4.9, 1.5.x - migration-facilitation Jan 5, 2016
@petebacondarwin petebacondarwin removed this from the 1.5.0-rc.1 milestone Jan 11, 2016
@simkessy
Copy link

When I change to window.Node.prototype.contains I now get the error Unable to get property 'prototype' of undefined or null reference

I'm using IE8 and trying to get angular running there.

@petebacondarwin
Copy link
Contributor

@simkessy - Versions of Angular after 1.2 do not support IE8

@simkessy
Copy link

@petebacondarwin - thanks for the response. I've begun reverting back to 1.2 (unfortunately)

@MaestroJurko
Copy link
Author

I am getting this issue in angular 1.5.3 version.

How to fix this?

Using jquery and d3.

@gkalpak
Copy link
Member

gkalpak commented Mar 29, 2016

@mato75, you need to make sure Node is available on the global context.

@MaestroJurko
Copy link
Author

Ok, thank you, but why is not the fix included with new versions of Angular library?

@gkalpak
Copy link
Member

gkalpak commented Mar 29, 2016

@mato75, this doesn't break any of the "officially" supported browsers (and so far there hasn't been any report of an issue that couldn't be solved on the developer's side).

But we are investigating if/how we can fix this and other similar issues, so it is easier for people running their code/tests in other environments (e.g. jsdom). This is not a high priority though, so don't expect a quick turnaround.

@petebacondarwin
Copy link
Contributor

@mato75 see #13442 (comment)

@mgol
Copy link
Member

mgol commented Mar 30, 2016

PR: #14345

mgol added a commit to mgol/angular.js that referenced this issue Mar 30, 2016
mgol added a commit to mgol/angular.js that referenced this issue Apr 6, 2016
mgol added a commit to mgol/angular.js that referenced this issue Apr 6, 2016
@mgol mgol closed this as completed in ddad264 Apr 6, 2016
mgol added a commit that referenced this issue Apr 6, 2016
@mgol mgol modified the milestones: 1.5.4, 1.5.x Apr 6, 2016
@MaestroJurko
Copy link
Author

MaestroJurko commented Jul 19, 2016

@gkalpak changing Node.prototype to window.Node.prototype doesnt solve this issue. Angular 1.5.7 + jquery 2.1.3 + Latest Chrome.

@mgol
Copy link
Member

mgol commented Jul 19, 2016

@mato75 If window.Node.prototype doesn't exist for you in Chrome then something must be really weird with your setup. We'd have to see a reproducible example, we can't do anything here if we don't see the code.

@MaestroJurko
Copy link
Author

Ah I see. It is a problem when using angularjs library in web worker.

@mgol
Copy link
Member

mgol commented Jul 19, 2016

That explains the problem. Angular 1 is not supported in Web Workers. What are you trying to do with Angular there? Since Web Workers don't have access to the DOM, most of the Angular functionality (directives/components, events, data binding etc.) disappears.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants