I use Angular 4 Universal Starter and integrated all my Angular 2 code in this starter. Everything works fine, but in the terminal I get this strange error. Not sure if the problem
ERROR TypeError: this.html.charCodeAt is not a function in Preprocessor.advance (/ home / user / node / project / dist / server.js: 152260: 24) in Tokenizer._consume (/ home / user / node / project / dist /server.js:45694:30) in Tokenizer.getNextToken (/home/user/node/project/dist/server.js:45652:23) in Parser._runParsingLoop (/ home / user / node / project / dist / server .js: 102429: 36) in Parser.parseFragment (/home/user/node/project/dist/server.js:102384:10) in Object.parseFragment (/home/user/node/project/dist/server.js : 55136: 19) in Parse5DomAdapter.setInnerHTML (/home/user/node/project/dist/server.js:53609:49) in Parse5DomAdapter.setProperty (/home/user/node/project/dist/server.js Decor3250 : 18) in EmulatedEncapsulationServerRenderer2.DefaultServerRenderer2.setProperty (/home/user/node/project/dist/server.js∗4766:94) in setElementProperty (/home/user/node/project/dist/server.js:9982:19)
This is because the code below is in server.js
Preprocessor.prototype.advance = function () {
this.pos++;
if (this.pos > this.lastCharPos) {
if (!this.lastChunkWritten)
this.endOfChunkHit = true;
return $.EOF;
}
var cp = this.html.charCodeAt(this.pos);
if (this.skipNextNewLine && cp === $.LINE_FEED) {
this.skipNextNewLine = false;
this._addGap();
return this.advance();
}
if (cp === $.CARRIAGE_RETURN) {
this.skipNextNewLine = true;
return $.LINE_FEED;
}
this.skipNextNewLine = false;
return cp >= 0xD800 ? this._processHighRangeCodePoint(cp) : cp;
};
this.html typeof returns "string", but the object below is returned before the error.
{ treeAdapter:
{ createDocument: [Function],
createDocumentFragment: [Function],
createElement: [Function],
createCommentNode: [Function],
appendChild: [Function],
insertBefore: [Function],
setTemplateContent: [Function],
getTemplateContent: [Function],
setDocumentType: [Function],
setDocumentMode: [Function],
getDocumentMode: [Function],
detachNode: [Function],
insertText: [Function],
insertTextBefore: [Function],
adoptAttributes: [Function],
getFirstChild: [Function],
getChildNodes: [Function],
getParentNode: [Function],
getAttrList: [Function],
getTagName: [Function],
getNamespaceURI: [Function],
getTextNodeContent: [Function],
getCommentNodeContent: [Function],
getDocumentTypeNodeName: [Function],
getDocumentTypeNodePublicId: [Function],
getDocumentTypeNodeSystemId: [Function],
isTextNode: [Function],
isCommentNode: [Function],
isDocumentTypeNode: [Function],
isElementNode: [Function] } }
Below is my generic server.ts
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import 'rxjs/Rx';
import * as express from 'express';
import { Request, Response } from 'express';
import { platformServer, renderModuleFactory } from '@angular/platform-server';
import { ServerAppModule } from './app/server-app.module';
import { ngExpressEngine } from '@nguniversal/express-engine';
import { ROUTES } from './routes';
import { enableProdMode } from '@angular/core';
enableProdMode();
const app = express();
const port = 4200;
const baseUrl = `http://localhost:${port}`;
app.engine('html', ngExpressEngine({
bootstrap: ServerAppModule
}));
app.set('view engine', 'html');
app.set('views', 'src');
app.use('/', express.static('dist', {index: false}));
app.get('/*', (req: Request, res: Response) => {
console.time(`GET: ${req.originalUrl}`);
res.render('../dist/index', {
req: req,
res: res
});
console.timeEnd(`GET: ${req.originalUrl}`);
});
app.listen(port, () => {
console.log(`Listening at ${baseUrl}`);
});
- Node: v6.9.2
- Angular: 4.1.0