1

I have recently migrated my angular 5 universal apps, to angular 6, I created it using ng generate universal command and followed below git hub link.

https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/universal-rendering.md#step-4-setting-up-an-express-server-to-run-our-universal-bundles

when I am running build command it showing error...

npm run build:SSR 

Error: __

ERROR in ./server.ts
Module not found: Error: Can't resolve './dist/server/main.bundle' in 'F:\angular_univarsal_tvtrd'
 @ ./server.ts 20:9-45

1 Answer 1

2

I have also upgraded from Angular 5 to 6 and I had the issue when building for universal. What I did was to download the sample app from the angular universal wiki and compared the files that I have with the ones discussed on the wiki.

It could be so many reasons why the build won't work for example, I have noticed one of my mistakes was with the script

"build:client-and-server-bundles": "ng build --prod && ng run MY-APP-NAME:server",

I had copied and pasted the one from the wiki but the name of my app was different. I have corrected this as my previous script was still using the --app which is no longer used but we now scope using --project as you can see the change in the new angular.json file which has a property of projects instead of apps.

Another thing could be that in your server.ts file you still have

const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main.bundle');

instead of

const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main');

Thus the best way I have solved this issue was to follow exactly what they are doing in the wiki and also compare the package versions they are using and updated mines to match their packages in the package.json those that are concerning Angular

Hope that'll help

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.