angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

bug(moment-adapter): "_rollupMoment__default is not defined"

Open kaito3desuyo opened this issue 6 years ago • 58 comments

(related with https://github.com/angular/angular/issues/36248)

Reproduction

https://github.com/kaito3desuyo/angular-test

Steps to reproduce:

  1. clone this repository
  2. ng build --prod
  3. npm i -g http-server
  4. move root directory to dist/angular-test Folder
  5. http-server
  6. 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

kaito3desuyo avatar Mar 26 '20 02:03 kaito3desuyo

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.

spock123 avatar Mar 30 '20 21:03 spock123

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.

demisx avatar Mar 31 '20 01:03 demisx

same here

albert-asin avatar Mar 31 '20 06:03 albert-asin

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.

alinaresz avatar Mar 31 '20 06:03 alinaresz

Same problem as @jasoninrapid Thank you for any updates.

neaptolem avatar Mar 31 '20 10:03 neaptolem

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.

showjefb avatar Mar 31 '20 15:03 showjefb

Lost one day looking for this 😢

Fzwael avatar Mar 31 '20 16:03 Fzwael

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 // the default as syntax. import * as _moment from 'moment'; // tslint:disable-next-line:no-duplicate-imports import {default as _rollupMoment, Moment} from 'moment';

const moment = _rollupMoment || _moment;

blogcraft avatar Mar 31 '20 21:03 blogcraft

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.

demisx avatar Mar 31 '20 22:03 demisx

The new @angular-devkit/build-angular has a problem compiling @angular/material-moment-adapter:

image

Possible workaround is just to add this to polyfills.ts:

window['_rollupMoment__default'] = null;

ViieeS avatar Apr 01 '20 08:04 ViieeS

Please note that this is not only problem with Moment - I'm getting the same error with ng2-dragula lib Zrzut ekranu 2020-03-31 o 12 57 20

gwidonw avatar Apr 01 '20 08:04 gwidonw

Same here with ng2-dragula after updating from 9.0.0 to 9.1.0..

mduft avatar Apr 01 '20 08:04 mduft

The new @angular-devkit/build-angular has a problem compiling @angular/material-moment-adapter:

image

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.

4typen avatar Apr 01 '20 09:04 4typen

Thank you @4typen, I was just trying to fix that and your workaround is much better!

mucbits avatar Apr 01 '20 09:04 mucbits

I tried to upgra to Angular 9.1.0 and a lot of libraries broken with errors like this.

quedicesebas avatar Apr 01 '20 17:04 quedicesebas

I just don't understand how to apply @mgechev fix or I don't understand why this issue is closed.

JosepAlacid avatar Apr 06 '20 18:04 JosepAlacid

@JosepAlacid the issue is fixed by this PR https://github.com/angular/angular-cli/pull/17364. We'll release the fix on Wednesday.

mgechev avatar Apr 06 '20 18:04 mgechev

I will go on until then with the "window['_rollupMoment__default'] = null;" workaround. Thanks for your kind response.

JosepAlacid avatar Apr 06 '20 20:04 JosepAlacid

image

danielehrhardt avatar Apr 06 '20 21:04 danielehrhardt

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

spock123 avatar Apr 06 '20 22:04 spock123