-
Notifications
You must be signed in to change notification settings - Fork 923
ReferenceError: self is not defined #1746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Also experiencing this issue after following the steps here https://fireship.io/lessons/angular-universal-firebase/ Before the part of adding firebase to the project, the built server.js file is working fine. However, after including firebase, the server.js file contains this line:
|
I managed to get it working again by adding the following code to my prerender.ts file =>
|
@mazlano27 |
@amit-ahire I placed it at the top of prerender.ts file as below => `import 'zone.js/dist/zone-node'; import {join, resolve} from 'path'; (global as any).self = {fetch: require('node-fetch')}; |
i got the same... |
where can you find the prerender.ts? |
Using GatsbyJS, can also confirm 5.11 onwards fails with an error during build. I was unable to get it working with the above (using the pre build hooks). 5.10 works fine. |
It is fixed by #1757 |
Can confirm it works. |
After Upgrading firebase to 6.0.2 /var/www/html/project-name/dist/server.js:228744 I faced this issue when with following version But it works if I switched it back to older version which is |
@raberana |
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
After updating to firebase 5.11.0 => I get the error:
Steps to reproduce:
Run pre-render script after updating to firebase 5.11.0
Angular 7 Project
My npm script:
"ng build --prod --stats-json && ng run myDayPwaApp:server && npm run webpack:prerender && npm run build:prerender",
"webpack:prerender": "webpack --config webpack.prerender.config.js",
"build:prerender": "node dist/myDayPwaApp/prerender.js"
and inside prerender.js =>
`// Load zone.js for the server.
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import {join, resolve} from 'path';
(global as any).WebSocket = require('ws');
(global as any).XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
import {enableProdMode} from '@angular/core';
// Import module map for lazy loading
import {provideModuleMap} from '@nguniversal/module-map-ngfactory-loader';
import {renderModuleFactory} from '@angular/platform-server';
import * as fs from 'fs-extra';
// Add routes manually that you need rendered
const ROUTES = [
'/',
'/auth/login',
'/auth/register',
'/auth/forgotten-password'
];
const APP_NAME = 'myDayPwaApp';
// leave this as require(), imported via webpack
const {
AppServerModuleNgFactory,
LAZY_MODULE_MAP
} = require(
./dist/${APP_NAME}-server/main
);enableProdMode();
async function prerender() {
// Get the app index
const browserBuild =
dist/${APP_NAME}
;const index = await fs.readFile(join(browserBuild, 'index.html'), 'utf8');
// Loop over each route
for (const route of ROUTES) {
const pageDir = join(browserBuild, route);
await fs.ensureDir(pageDir);
}
await fs.copySync(resolve(
dist/${APP_NAME}/index.html
),dist/${APP_NAME}/404.html
);console.log('done');
process.exit();
}
prerender();
`
The text was updated successfully, but these errors were encountered: