Error with angular 9 SSR and fire base cloud functions
I have been trying for two days now, I'm front end developer so I don't have the require experience to use node and the cloud function
I don't know if the following information is sufficient
so if you need any more information ask please
this is the log of fire base
Error: Cannot find module '/srv/dist/coupons/server'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at exports.universal.functions.https.onRequest (/srv/lib/index.js:5:5)
at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:49:9)
at /worker/worker.js:783:7
at /worker/worker.js:766:11
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickDomainCallback (internal/process/next_tick.js:219:9)
and this is my index.ts
import * as functions from 'firebase-functions';
export const universal = functions.https.onRequest((request, response) => {
require(`${process.cwd()}/dist/coupons/server`).app(request, response);
});
and this is sever.ts
import 'zone.js/dist/zone-node';
import { ngExpressEngine } from '@nguniversal/express-engine';
import * as express from 'express';
import { join } from 'path';
import { AppServerModule } from './src/main.server';
import { APP_BASE_HREF } from '@angular/common';
import { existsSync } from 'fs';
// The Express app is exported so that it can be used by serverless Functions.
export function app() {
const server = express();
const distFolder = join(process.cwd(), 'dist/coupons/browser');
const indexHtml = existsSync(join(distFolder, 'index.original.html'))
? 'index.original.html'
: 'index';
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
server.engine(
'html',
ngExpressEngine({
bootstrap: AppServerModule
})
);
server.set('view engine', 'html');
server.set('views', distFolder);
// Example Express Rest API endpoints
// app.get('/api/**', (req, res) => { });
// Serve static files from /browser
server.get(
'*.*',
express.static(distFolder, {
maxAge: '1y'
})
);
// All regular routes use the Universal engine
server.get('*', (req, res) => {
res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] });
});
return server;
}
function run() {
const port = process.env.PORT || 4000;
// Start up the Node server
const server = app();
server.listen(port, () => {
console.log(`Node Express server listening on http://localhost:${port}`);
});
}
// Webpack will replace 'require' with '__webpack_require__'
// '__non_webpack_require__' is a proxy to Node 'require'
// The below code is to ensure that the server is run only when not requiring the bundle.
declare const __non_webpack_require__: NodeRequire;
const mainModule = __non_webpack_require__.main;
const moduleFilename = (mainModule && mainModule.filename) || '';
if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
run();
}
export * from './src/main.server';
i followed this guide to convert the app to SSR
Deploying your Universal application on Cloud Functions for Firebase
any help would be appreciated
Universal in Angular 9 has had a lot changed & most of our instructions are outdated. The next RC for 6 will see the release of a schematic for universal support on Cloud Functions. Standby.
Universal in Angular 9 has had a lot changed & most of our instructions are outdated. The next RC for 6 will see the release of a schematic for universal support on Cloud Functions. Standby.
Any information about how much it's going to take to be released?
The next RC was released today, this includes support for schematic deploys of Universal apps to Hosting & Cloud Functions.
Could you provide link please, I could not find any updated docs for deployment
https://github.com/angular/angularfire/blob/master/docs/deploy/getting-started.md
https://github.com/angular/angularfire/blob/master/docs/deploy/getting-started.md
thank you very very much
one last thing, what does it mean
If you've specified that you want a server-side rendering enabled deployment in a firebase function, the command will also
because this is exactly what I need
and also,
ng deploy --preview
gives
Unknown option: '--preview'
thanks in advance, sorry for asking to much
is there a chance you would update the following docs? https://github.com/angular/angularfire/tree/master/docs/universal
I'm successful runing angular universal with angular 9.1 and @angular/fire 6RC2 at here https://github.com/hiepxanh/angular-fire-universal @khaled6mmd I just create an PR here https://github.com/angular/angularfire/pull/2372/files?short_path=e76f33d#diff-e76f33db0439ee8e320dfa7ecf47f09b let's check this out @jamesdaniels can you review my PR? https://github.com/angular/angularfire/pull/2372
I'm successful runing angular universal with angular 9.1 and @angular/fire 6RC2 at here https://github.com/hiepxanh/angular-fire-universal @khaled6mmd I just create an PR here https://github.com/angular/angularfire/pull/2372/files?short_path=e76f33d#diff-e76f33db0439ee8e320dfa7ecf47f09b let's check this out @jamesdaniels can you review my PR? #2372
thank you very much for the efforts
I follow you instructions and it gave me the following
Built at: 04/01/2020 4:18:16 PM
Asset Size Chunks Chunk Names
main.js 3.93 MiB 0 [emitted] [big] main
Entrypoint main [big] = main.js
chunk {0} main.js (main) 7.37 MiB [entry] [rendered]
⚠️ Your Node.js version (13.12.0) does not match the Firebase Functions runtime (10).
Deploying your Angular Universal application...
success.hosting.split is not a function
PS C:\Users\Khaled\Desktop\coupons>

@khaled6mmd please follow this instruction https://firebase.google.com/docs/functions/manage-functions
![]()
@khaled6mmd please follow this instruction https://firebase.google.com/docs/functions/manage-functions
I use nvm to do so, did not help
@khaled6mmd the error you posted seems to indicate that you're using an unsupported version of Node, maybe your nvm setup is not working correctly.
@khaled6mmd the error you posted seems to indicate that you're using an unsupported version of Node, maybe your nvm setup is not working correctly.
@jamesdaniels installed node 10.13 as it's the minimum to run ng cli and it gives same error
@hiepxanh , could you add to your repo your functions folder to have an example off ssr functions ? I can't manage to make it work with :
export const universal = functions.https.onRequest((request, response) => {
require(${process.cwd()}/dist/server/main).app(request, response);
});
@hiepxanh , could you add to your repo your functions folder to have an example off ssr functions ? I can't manage to make it work with :
export const universal = functions.https.onRequest((request, response) => { require(${process.cwd()}/dist/server/main).app(request, response); });
it gets created automatically if you follow this guide
https://github.com/angular/angularfire/blob/master/docs/deploy/getting-started.md
then run
npm i @angular/[email protected] --save
then
https://github.com/angular/angularfire/pull/2372/files#diff-e76f33db0439ee8e320dfa7ecf47f09b
Getting " Command failed: npm ls || true " as raised here
Getting " Command failed: npm ls || true " as raised here
but it does work fine with me,
ng deploy --project=**** and ng deploy --preview
work fine for me, I get another error so I think I need to close this issue and create another one for the issue I have now
Hi @khaled6mmd what was the solution to this issue? I have the same