I deployed my node.js / Angular application on an AWS EC2 Ubuntu instance. When opening the project in a browser, all lazy loaded modules don't work. The modules never complete loading, although they start loading.
The weird thing about this is, that when deploying the app to Heroku or testing it with localhost everything works fine. (In production build).
Here is what the network tab looks like when deployed to the AWS EC2 instance (not loading lazy modules): 
Here is what the network tab looks like when deployed to Heroku (works fine): 
Here is what the network tab looks like when run on localhost (works fine): 
Furthermore, there are no errors occurring in the console.
app.routes.ts
export const routes: Routes = [
{
path: 'auth',
loadChildren: './auth/auth.module#AuthModule',
},
{
path: 'seller',
canActivate: [guards.AuthGuard, guards.SellerGuard],
loadChildren: './features/seller/seller.module#SellerModule',
},
{
path: 'shopping',
loadChildren: './features/shopping/shopping.module#ShoppingModule',
},
{
path: 'products',
loadChildren: './features/products/products.module#ProductsModule',
},
{
path: 'me',
canActivate: [guards.AuthGuard],
loadChildren: './features/me/me.module#MeModule',
},
{
path: 'search',
loadChildren: './features/search/search.module#SearchModule',
},
{
path: 'business',
loadChildren: './features/business/business.module#BusinessModule',
},
{
path: 'users',
loadChildren: './features/users/users.module#UsersModule',
},
{
path: '**',
redirectTo: ''
},
];
node-server.js
// many other configurations
app.use('/api', api)
app.get('*', (req, res) => {
res.status(200).sendFile(path.join(__dirname, './client/index.html'))
})
app.listen(port, () => {
console.log(`• Server launched 🚀 on port`, port)
console.log(`• Server running in ${prod ? '🔥 production' : '💉 development'} mode`)
console.log(`• • •`)
})
I can't really post detailed code, because it's a very big project and I don't know what causes the error. So let me know if I should add some specific file(s).
from Node.js / Angular 7 - Lazy Modules Routing not Working in Production Build with AWS EC2
No comments:
Post a Comment