Closed theunreal closed 1 year ago
With the latest answers, I've had navigator is not defined
, which has an easy fix (global as any).navigator = win.navigator;
.
Later, TypeError: Cannot read property 'charAt' of undefined
popped up. It was doable to have it fixed by removing(global as any).XMLHttpRequest = require('xhr2');
Apparently, the xhr2
and ws
packages weren't needed, and the code could've been dropped as well
(global as any).WebSocket = require('ws');
(global as any).XMLHttpRequest = require('xhr2');
I've also simplified this part
const distFolder = join(process.cwd(), 'dist/nbinar/browser');
const indexHtml = 'index.html';
const template = readFileSync(join(distFolder, indexHtml)).toString();
const win = createWindow(template);
into
const indexHtml = join(
process.cwd(),
'dist/nbinar/browser/index2.html'
);
const win = createWindow(indexHtml);
It left me with the whole code as lean as possible
import { createWindow } from 'domino';
import { join } from 'path';
const indexHtml = join(
process.cwd(),
'dist/nbinar/browser/index2.html'
);
const win = createWindow(indexHtml);
// Polyfills
(global as any).window = win;
(global as any).document = win.document;
(global as any).navigator = win.navigator;
All in server.ts
, other files were completely fine. Of course, I've excluded the 3 useless packages from package.json
, i.e. fs
, xhr2
, and ws
.
Many thanks for contribution to fixing such an irritating error.
PS. Works fine on Angular 10
, locally rendered by Cloud Functions for Firebase
as well as once deploying to Firebase
.
@danieldanielecki @michelepatrassi, after several hours and tests done, I almost gave up, but thanks to your answers I was able to compile my project in Angular Universal.
this is my config:
I am glad to hear that!! :)
nebular needs to fix this, domino is not a valid option as the package itself is HUGE and SLOW!
Window is not defined
Angular universal
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.
I'm submitting a ...
[ x] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, see note at the top of this template.
What modules are related to this Issue?
[ ] aspnetcore-engine
[x ] express-engine
[ ] hapi-engine
Do you want to request a feature or report a bug? bug
What is the current behavior? I followed this tutorial: https://github.com/angular/angular-cli/wiki/stories-universal-rendering used node
dist/server.js
and got this message as expected:but when I'm trying to access my localhost:4000 I get this in the console:
What is the expected behavior? Should access my angular project instead throwing an error
What is the motivation / use case for changing the behavior? bug fix
Please tell us about your environment:
Angular version: 4.0.0
Browser: all
Language:all
OS: Windows
Platform:NodeJS
Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)