Open frenci8 opened 2 years ago
@frenci8 did you get some solution on your problem? We have the same problem, when injecting REQUEST / RESPONSE via server.ts:
server.get('*', (req: Request, res: Response) => {
res.render(indexHtml, {
req,
providers: [
{ provide: APP_BASE_HREF, useValue: req.baseUrl },
{ provide: 'REQUEST', useValue: req },
{ provide: 'RESPONSE', useValue: res },
],
});
});
When using the tokens later in the app code, we get the same error as you mentioned above..
@janwidmer Hi, unfortunately, I have not found a solution, but if you find one, feel free to share it here.
@dunqan @Platonn any statement from you guys if that should work with CCV2? Error does also seem to Occur for Injection Token SERVER_REQUEST_URL
WITHOUT ANY usage of any injection tokens in my code..
Has there been a recent change in the CCV2 Cloud which breaks the usage of such tokens? According to ticket https://github.com/SAP/spartacus/issues/11016 I would understand that they should work in general?
@frenci8 I have tracked down the issue to invalid combinations of dependency versions of the following packages:
// working
"@angular/platform-server": "~12.2.0",
"@angular/service-worker": "~12.2.0",
"@nguniversal/express-engine": "~12.1.3",
// not working (in cloud)
"@angular/platform-server": "~12.0.5",
"@angular/service-worker": "~12.0.5",
"@nguniversal/express-engine": "~12.0.2",
// not working (in cloud)
"@angular/platform-server": "~12.2.0",
"@angular/service-worker": "~12.2.0",
"@nguniversal/express-engine": "~12.0.2",
In my case, I was somehow using the second / third combination, which was leading to that error
A note on Caret (^) vs Tilde (~): Spartacus generates the package json for a fresh spartacus by adding carets (^) for all dependencies. This approach is kinda dangerous because it lets the system use any minor version of packages from the set version and above.
Therefore we usually replace the caret with tilde or even with a fix pinned version. This now caused the above exception to be throughn when starting spartacus in production ssr mode.
If the above package version combinations still don't work, I recommend you to generate a fresh spartacus instance on the current version and take the exact version combinations from there.
@dunqan @Platonn would it make sense to increase the min version of @nguniversal/express-engine
to 12.1.3
(when generating / updating a spartacus via schematics? There are several people having this problem (see slack help channel)
Hello,
I am using spartacus and I would like to render static versions of pages on the server side. I added SSR support using the manual instructions on this page https://sap.github.io/spartacus-docs/server-side-rendering-in-spartacus/ followed by support for domino in order to fix the error
ReferenceError: window is not defined
.I run angular now using either one of the 2 following commands:
npm run dev:ssr
ornpm run build:ssr && npm run serve:ssr
and I get the following error:REQUEST is not being used in any of the modules created by me, so I am not sure where to provide REQUEST. Any has any ideas why this error happens and how to fix it?
Thank you