question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

innerHTML throws ERROR ReferenceError: Node is not defined

See original GitHub issue

I’m submitting a …

- [X] bug report <!-- Please search GitHub for a similar issue or PR before submitting -->
- [ ] feature request
- [ ] Support request => Please do not submit support request here, instead see https://github.com/angular/universal/blob/master/CONTRIBUTING.md#question

What modules are related to this Issue?

- [ ] aspnetcore-engine
- [ ] common
- [X] express-engine
- [ ] hapi-engine
- [X] module-map-ngfactory-loader

Current behavior?

Binding [innerHTML] to an element in a component template throws the following server-side error when serving an angular universal app:

Node server listening on http://localhost:4000
Running on the server with appId=tour-of-heroes
ERROR ReferenceError: Node is not defined
    at isTemplateElement (/Users/dbellizio/Dev/angular/universal/dist/server.js:12053:28)
    at getTemplateContent (/Users/dbellizio/Dev/angular/universal/dist/server.js:12048:65)
    at _sanitizeHtml (/Users/dbellizio/Dev/angular/universal/dist/server.js:12040:28)
    at DomSanitizerImpl.sanitize (/Users/dbellizio/Dev/angular/universal/dist/server.js:82748:92)
    at setElementProperty (/Users/dbellizio/Dev/angular/universal/dist/server.js:12999:61)
    at checkAndUpdateElementValue (/Users/dbellizio/Dev/angular/universal/dist/server.js:12951:13)
    at checkAndUpdateElementInline (/Users/dbellizio/Dev/angular/universal/dist/server.js:12898:24)
    at checkAndUpdateNodeInline (/Users/dbellizio/Dev/angular/universal/dist/server.js:15234:20)
    at checkAndUpdateNode (/Users/dbellizio/Dev/angular/universal/dist/server.js:15200:16)
    at prodCheckAndUpdateNode (/Users/dbellizio/Dev/angular/universal/dist/server.js:15744:5)

Expected behavior?

The server-side error should not occur and the app should render normally as expected.

Minimal reproduction with instructions

  1. Download and unzip the universal sample app from Angular here
  2. Run npm install in the universal directory
  3. Open app.component.ts and change the title property to the following: title = '<h1>Tour of Heroes</h1>';
  4. Open app.component.html, remove the h1 tag, and add the following in its place: <div [innerHTML]="title"></div>
  5. Run npm run build:ssr
  6. Run npm run serve:ssr
  7. Navigate to localhost:4000
  8. Observe the error code pasted above in the terminal console

Environment:

@nguniversal versions

  • express-engine: 6.0.0-rc.2
  • module-map-ngfactory-loader: 6.0.0-rc.2
Your global Angular CLI version (6.0.0) is greater than your local
version (6.0.0-rc.4). The local Angular CLI version is used.

To disable this warning use "ng config -g cli.warnings.versionMismatch false".

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


Angular CLI: 6.0.0-rc.4
Node: 8.11.1
OS: darwin x64
Angular: 6.0.0
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router, upgrade

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.5.13
@angular-devkit/build-angular     0.5.13
@angular-devkit/build-optimizer   0.5.13
@angular-devkit/core              0.5.13
@angular-devkit/schematics        0.5.6
@angular/cli                      6.0.0-rc.4
@ngtools/json-schema              1.1.0
@ngtools/webpack                  6.0.0-rc.11
@schematics/angular               0.5.6
@schematics/update                0.5.6
rxjs                              6.0.0-uncanny-rc.7
typescript                        2.7.2
webpack                           4.6.0

Other information (optional)

The error occurs on the official 6.0.0 release of Angular / Angular CLI / Angular Universal as well.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
Toxicablecommented, May 10, 2018

ah yes I am able to reproduce it with yarn I must have made a mistake earlier. Thanks for reporting this, i’ll investigate further

0reactions
angular-automatic-lock-bot[bot]commented, Sep 4, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

First time using node.js - "ReferenceError: node is not defined"
It looks like you have entered the node REPL and then typed node -v. The good news is that this means node is...
Read more >
ReferenceError: document is not defined in JavaScript
The "ReferenceError: document is not defined" error occurs for multiple reasons: Using document in Node.js. Using document on the server (e.g. server side ......
Read more >
referenceerror: document is not defined at object.<anonymous>
You are running in Node.js, which does not have a window or document. If you want to run it in a browser, add...
Read more >
JavaScript Errors Try Catch Throw - W3Schools
The catch statement defines a code block to handle any error. ... A ReferenceError is thrown if you use (reference) a variable that...
Read more >
Optional chaining '?.' - The Modern JavaScript Tutorial
As user.address is undefined , an attempt to get user.address.street ... innerHTML; // error if it's null ... innerHTML property of null ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found