Search code examples
angulartypescriptangular12

Angular update from 10 to 12 ssr issue


I did upgrade Angular version from 10 to 11 and then from 11 to 12 from Angular documentation on advanced app complexity everything works fine but when i tried to build project with Angular universal I'm experiencing error below :

./server.ts - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js): Error: /Users/bobvv/kl-front/server.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property. at /Users/bobvv/kl-front/node_modules/@ngtools/webpack/src/ivy/loader.js:59:26

and every ts file that is for angular universal is viewing * is part of the TypeScript compilation but it's unused. Add only entry points to the 'files' or 'include' properties in your tsconfig.


Solution

  • I was trying to run both local and build version of my angular project with old commands from angular 10 which was causing this issue. For building angular 12 on localhost you should use ng run {{project-name}}:serve-ssr which is added to your package.json by default so you can use npm run dev:ssr and for build version you should use ng run {{project-name}}:prerender and then node dist/{{project-name}}/server/main.js which by default is added to your package.json so you can use npm run prerender and then npm run serve:ssr