问题
I have just upgraded our project to Angular 4.1.0. This also included upgrading webpack to 2.2.1, and upgrading ngx-boostrap to 1.9.2 amongst other package upgrades.
After upgrading all this, I tested everything with webpack dev server, in dev mode and all was fine. I then tried a production webpack build. The build worked fine, but upon running our site I immediately get the error 'Cannot enable prod mode after platform setup'.
Having investigated using Chrome dev tools, I can see that ngx-bootstrap/utils/warn-once.js is calling isDevMode() during startup. This happens before the call to enableProdMode() in our main.ts. The angular code doesn't allow the mode to be changed after it has been checked, so throws the error. That part I understand.
However, my knowledge of webpack goes as far as having it work for our project and no further. I have no idea what is at fault here. Is it:
1) That ngx-bootstrap shouldn't be calling isDevMode() as it starts up.
2) That I have webpack configured incorrectly, and the call to isDevMode should be happening after main.ts is run (however none any of our code has changed since this was all working fine before the upgrade).
3) Something else
Apologies that this is a vague question. I just don't have enough understanding of webpack to ask it more accurately. Any help would be much appreciated.
Thanks
回答1:
Update ngx-bootstrap to 1.9.3, this release has fixed that issue.
回答2:
I had the same problem upgrading to Angular 4.3.4. I did two things to fix it:
- Upgraded the globally installed
@angular/cli
to match the version in the project's package.json. I used@angular/cli
1.4.0 but you might need an older version for Angular 4.1.0, I'm not sure. - Generated a new project with that CLI version and compared
package.json
,.angular-cli.json
,tsconfig.json
andmain.ts
from the generated project with the project being upgraded.
来源:https://stackoverflow.com/questions/46151750/isdevmode-enableprodmode-error-cannot-enable-prod-mode-after-platform-setup