maciejtreder / ng-toolkit

:star: Angular tool-box! Start your PWA in two steps! Add Serverless support for existing projects and much more
https://www.angular-universal-pwa.maciejtreder.com
MIT License
1.12k stars 156 forks source link

Not able to run build:prod #376

Open shyamal890 opened 6 years ago

shyamal890 commented 6 years ago

I'm submitting a...


[ x] Bug report  
[ ] Feature request
[ ] Documentation issue or request

In package


[ ] @ng-toolkit/init
[ ] @ng-toolkit/serverless
[ x] @ng-toolkit/universal

Current behavior

On running npm run build:prod. It gives error saying component modules cannot be found at their respective location. While npm run hmr gives error saying BrowserPlatform is needed

Expected behavior

Minimal reproduction of the problem with instructions

Adding a zip file with the repository.

Environment


Angular version: 6.0.3


Browser:
- [x ] Chrome (desktop) version 67
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX

For Tooling issues:
- Node version: XX  
- Platform:  

for test.zip

shyamal890 commented 6 years ago

Hi any updates on this?

maciejtreder commented 6 years ago

@shyamal890 Nope so far. I think that today I will find a little bit of time to take a look at this.

shyamal890 commented 6 years ago

Ok so I was able to solve the issues. Listing out the changes that solved the issue:

  1. I had custom code in main.ts mainly for hmr. So after including ng-toolkit, I needed to change AppModule to AppBrowserModule.
const bootstrap = () => platformBrowserDynamic().bootstrapModule(AppModule); <-- CHANGED THIS

if (environment.hmr) {
  var module: {}; 
  if (module[ 'hot' ]) {
    hmrBootstrap(module, bootstrap);
  } else {
    console.error('HMR is not enabled for webpack-dev-server!');
    console.log('Are you using the --hmr flag for ng serve?');
  }
} else {
  bootstrap();
}
  1. Had to comment out "baseUrl": "./", in tsconfig.server.json as it was giving path errors otherwise. Still don't know why it didn't work properly.

  2. There is some issue when ng-toolkit tries to wrap window.