bug(moment-adapter): "_rollupMoment__default is not defined"
(related with https://github.com/angular/angular/issues/36248)
Reproduction
https://github.com/kaito3desuyo/angular-test
Steps to reproduce:
- clone this repository
ng build --prodnpm i -g http-server- move root directory to
dist/angular-testFolder http-server- open
http://localhost:8080
This issue only occurs with production builds.
Expected Behavior
Screen is displayed correctly
Actual Behavior
Screen goes blank with console error
Environment
- Angular: 9.1.0
- CDK/Material: 9.2.0
- Browser(s): Chrome 80.0.3987.149
- Operating System (e.g. Windows, macOS, Ubuntu): Windows 10 x64 1909 18363.720
I think most of us are stuck on 9.0.x for now. I can't risk workarounds or downgraded dependencies. Better to wait until this gets sorted out - at least for me.
Same issue after upgrading Angular to the latest. Had to downgrade @angular-devkit/build-angular to v0.900.7 to get rid of the same error as @ArtemeeSenin's.
same here
Same problem after upgrading to "@angular-devkit/build-angular": "^0.901.0" The workaround by @jnfaerch to downgrade to "^0.900.7", worked for me.
Same problem as @jasoninrapid Thank you for any updates.
Took a while to track down (wish I had visited here first), but I have the same scenario as many. 0.900.7 works while 0.901.0 breaks my build versions.
Lost one day looking for this 😢
ISSUE RESOLVED
Issue is not resolved, this is a workaround. We should'nt have to downgrade or change moment import.
Actually, that's how Angular Material docs recomends using moment: https://material.angular.io/components/datepicker/overview
// Depending on whether rollup is used, moment needs to be imported differently. // Since Moment.js doesn't have a default export, we normally need to import using the
* as// syntax. However, rollup creates a synthetic default module and we thus need to import it using // thedefault assyntax. import * as _moment from 'moment'; // tslint:disable-next-line:no-duplicate-imports import {default as _rollupMoment, Moment} from 'moment';const moment = _rollupMoment || _moment;
Please note that this issue breaks the prod build even for those who don't use Moment.js and _rollupMoment. Some regression has been introduced going from 0.900.7 to 0.901.0.
The new @angular-devkit/build-angular has a problem compiling @angular/material-moment-adapter:

Possible workaround is just to add this to polyfills.ts:
window['_rollupMoment__default'] = null;
Please note that this is not only problem with Moment - I'm getting the same error with ng2-dragula lib

Same here with ng2-dragula after updating from 9.0.0 to 9.1.0..
The new
@angular-devkit/build-angularhas a problem compiling@angular/material-moment-adapter:
Possible workaround is just to add this to
polyfills.ts:
window['_rollupMoment__default'] = null;
This is probably the better workaround instead of downgrading the angular-devkit.
I have btw. the same issue with "getAngularJSGlobal" and "_rollupMoment__default" in our AngularJS/Angular 9.1 Hybrid App.
Thank you @4typen, I was just trying to fix that and your workaround is much better!
I tried to upgra to Angular 9.1.0 and a lot of libraries broken with errors like this.
I just don't understand how to apply @mgechev fix or I don't understand why this issue is closed.
@JosepAlacid the issue is fixed by this PR https://github.com/angular/angular-cli/pull/17364. We'll release the fix on Wednesday.
I will go on until then with the "window['_rollupMoment__default'] = null;" workaround. Thanks for your kind response.

@danielehrhardt Is that with @mgechev 's fix or?