I am trying to install Angular Universal to my existing app via ng add @nguniversal/express-engine
as per documentation but am running into a couple of issues:
When I run that command I'm getting that the detected compatible version is
7.0.1
:Found compatible package version: @nguniversal/express-engine@7.0.1.
which is a 4-year old version, whereas if I run that on a brand new, clean project I get version14.1.0
. If I go ahead and use7.0.1
then I get an error aboutid
,$id
or something like that not being supported and the command exits, so as a workaround I ranng add @nguniversal/express-engine@14.1.0
which completed successfully but this leads to the following issues.If I then try to run
npm run dev:ssr
I get this error:error TS2339: Property 'removeAllListeners' does not exist on type 'Window & typeof globalThis'.
which I was able to resolve by adding:
declare global {
interface Window {
removeAllListeners: any;
}
}
at the bottom of my app.module.ts
file.
- But I also get this other error:
./node_modules/@angular/platform-server/fesm2015/platform-server.mjs:1372:27-53 - Error: export 'ɵinternalCreateApplication' (imported as 'ɵinternalCreateApplication') was not found in '@angular/core' (possible exports: ANALYZE_FOR_ENTRY_COMPONENTS, ANIMATION_MODULE_TYPE, APP_BOOTSTRAP_LISTENER, APP_ID, ........
I think this is probably related to the version mismatch thing when I first added Universal to my project but I don't really know where to go from here since I double checked and my dependencies versions are the same as a new, clean project.
This is my package.json
:
{
"name": "test",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "node server/server.js",
"start:dev": "ng serve",
"start:docker": "ng serve --host 0.0.0.0 --disable-host-check",
"build": "npx @angular/cli build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"docs:json": "compodoc -p ./tsconfig.json -e json -d .",
"storybook": "npm run docs:json && start-storybook -p 6006",
"build-storybook": "npm run docs:json && build-storybook",
"dev:ssr": "ng run test:serve-ssr",
"serve:ssr": "node dist/test/server/main.js",
"build:ssr": "ng build && ng run test:server",
"prerender": "ng run test:prerender"
},
"private": true,
"dependencies": {
"@angular-devkit/build-angular": "^14.0.5",
"@angular/animations": "^14.0.0",
"@angular/common": "^14.0.0",
"@angular/compiler": "^14.0.0",
"@angular/compiler-cli": "^14.0.0",
"@angular/core": "^14.0.0",
"@angular/forms": "^14.0.0",
"@angular/google-maps": "^14.1.3",
"@angular/platform-browser": "^14.0.0",
"@angular/platform-browser-dynamic": "^14.0.0",
"@angular/platform-server": "^14.0.0",
"@angular/router": "^14.0.0",
"@ng-select/ng-select": "^9.0.2",
"@nguniversal/express-engine": "^14.1.0",
"angular2-collapsible": "^0.8.0",
"dayjs": "^1.11.4",
"express": "^4.15.2",
"express-http-proxy": "^1.6.3",
"iotacss": "^1.6.0",
"ngx-smart-modal": "^7.4.1",
"rxjs": "~7.5.0",
"swiper": "~8.1.0",
"tslib": "^2.3.0",
"typescript": "~4.7.2",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular/cli": "~14.0.5",
"@babel/core": "^7.18.9",
"@compodoc/compodoc": "^1.1.19",
"@nguniversal/builders": "^14.1.0",
"@storybook/addon-actions": "^6.5.9",
"@storybook/addon-essentials": "^6.5.9",
"@storybook/addon-interactions": "^6.5.9",
"@storybook/addon-links": "^6.5.9",
"@storybook/angular": "^6.5.9",
"@storybook/builder-webpack5": "^6.5.9",
"@storybook/manager-webpack5": "^6.5.9",
"@storybook/testing-library": "^0.0.13",
"@types/express": "^4.17.0",
"@types/jasmine": "~4.0.0",
"@types/node": "^14.15.0",
"babel-loader": "^8.2.5",
"jasmine-core": "~4.1.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.0.0",
"karma-jasmine-html-reporter": "~1.7.0"
}
}