angular-cli: 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:

  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

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 80
  • Comments: 58 (7 by maintainers)

Commits related to this issue

Most upvoted comments

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;

Edit: Noted wrong package šŸ˜•

Can recreate with "@angular-devkit/build-angular": "~0.901.0"

ā€œResolvedā€ with "@angular-devkit/build-angular": "~0.900.7"

ISSUE RESOLVED

Issue is not resolved, this is a workaround. We shouldā€™nt have to downgrade or change moment import.

I spent some time investigating it and itā€™s most-likely an issue with build-angular like mentioned above. Iā€™ve narrowed it down to somewhere between 0.900.3 and 0.901.0-next.4. The issue comes from the following lines:

var Jg = n("wd/R");
const Zg = _rollupMoment__default || Jg

Compared to the ones from a working version:

Ng = n("wd/R"),
Vg = n.n(Ng).a || Ng

Iā€™m transferring the issue over to the correct repo.

Same problem

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.

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

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

Lost one day looking for this šŸ˜¢

I tried the new version 9.1.1, that has been released today, and it solved the issue for me.

Same problem here in production build only with ā€œ@angular-devkit/build-angularā€: ā€œ~0.901.0ā€. Downgraded for now.

Yep, also seeing this issue with moment after upgrading

Have the same problem but with main-es2015.8a5dc9b260c775d8aa4b.js:1 Uncaught ReferenceError: dragulaExpt__default is not defined (ā€œ@angular-devkit/build-angularā€: ā€œ~0.901.0ā€)

@wasiddiqui, ~0.907.0 worked for me. My project is using another lib, that was also built with ~0.901.0. once Iā€™ve rebuilt that lib and my project, the issue has gone. So you might need to check your dependencies.

Same Here: image

@JACrazy no need to go back to 3.6. We fixed this issue and published the fix on npm.

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 fix is not our yet. @danielehrhardt did you build the CLI from source?

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

As @OckePocke mentioned, we released CLI 9.1.1 today. If the problem still persist for you, feel free to open a new issue linking this one.

I think this is because angular-cli has not been released yet, still in v9.1.0.

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

Same here with ng2-dragula after updating from 9.0.0 to 9.1.0ā€¦

Same problem with the production build.