angular-google-maps icon indicating copy to clipboard operation
angular-google-maps copied to clipboard

Failed to display maps in page. ERROR TypeError: Object(...) is not a function

Open petalyaa opened this issue 8 years ago • 22 comments

I followed exactly steps in Getting Started, however I got error during page load and the maps cannot be load.

Steps to reproduce

  1. Install agm core module through terminal npm install @agm/core --save

  2. Include AgmCoreModule in app.module.ts

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { AppComponent } from './app.component';
    import { AgmCoreModule } from '@agm/core';
    
    @NgModule({
        declarations: [
            AppComponent
        ],
        imports: [
            BrowserModule,
            AgmCoreModule.forRoot({
              apiKey : 'my_api_key'
            })
        ],
        providers: [],
        bootstrap: [AppComponent]
    })
    export class AppModule { }
    
  3. Add <agm-map /> component in my html

    <agm-map [latitude]="latitude" [longitude]="longitude">
    </agm-map>
    
  4. Add height to <agm-map /> component in my app.component.scss

    agm-map {
        height : 600px;
    }
    
  5. Add latitude and longitude property in app.component.ts

    import { Component } from '@angular/core';
    
    @Component({
        selector: 'app-root',
        templateUrl: './app.component.html',
        styleUrls: ['./app.component.scss']
    })
    export class AppComponent {
        latitude: number = 51.678418;
        longitude: number = 7.809007;
    
        constructor(){}
    
    }
    
  6. Run the application using ng serve command

  7. Open http://localhost:4200 in my browser just to see blank page with below's error in developer console.

    ERROR TypeError: Object(...) is not a function
    at new FitBoundsService (fit-bounds.js:31)
    at createClass (core.js:12481)
    at _createProviderInstance (core.js:12458)
    at createProviderInstance (core.js:12299)
    at createViewNodes (core.js:13771)
    at callViewAction (core.js:14218)
    at execComponentViewsAction (core.js:14127)
    at createViewNodes (core.js:13812)
    at createRootView (core.js:13673)
    at callWithDebugContext (core.js:15098)
    

Expected/desired behavior I want to display a map without any marker in it.

angular2 & angular-google-maps version

Angular CLI: 1.6.8
Node: 9.5.0
OS: linux x64
Angular: 5.2.11
    ... animations, common, compiler, compiler-cli, core, forms
    ... http, language-service, platform-browser
    ... platform-browser-dynamic, router

@angular/cli: 1.6.8
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.0.29
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.8
@schematics/angular: 0.1.17
typescript: 2.5.3
webpack: 3.10.0

AGM Version : @agm/[email protected]

petalyaa avatar Sep 27 '18 09:09 petalyaa

Same thing here in angular 6. It stopped working in beta 4; beta 3 still works as it should.

giorgiopagnoni avatar Sep 28 '18 10:09 giorgiopagnoni

Same here.

When i look at the source map, for me it's throwing an error at line 31 where it's setting this.bounds$ within the FitBoundsService constructor.

import { Injectable } from '@angular/core';
import { BehaviorSubject, from, timer } from 'rxjs';
import { flatMap, map, sample, switchMap, shareReplay } from 'rxjs/operators';
import { MapsAPILoader } from './maps-api-loader/maps-api-loader';
/**
 * Class to implement when you what to be able to make it work with the auto fit bounds feature
 * of AGM.
 */
var /**
 * Class to implement when you what to be able to make it work with the auto fit bounds feature
 * of AGM.
 */
FitBoundsAccessor = /** @class */ (function () {
    function FitBoundsAccessor() {
    }
    return FitBoundsAccessor;
}());
/**
 * Class to implement when you what to be able to make it work with the auto fit bounds feature
 * of AGM.
 */
export { FitBoundsAccessor };
/**
 * The FitBoundsService is responsible for computing the bounds of the a single map.
 */
var FitBoundsService = /** @class */ (function () {
    function FitBoundsService(loader) {
        var _this = this;
        this._boundsChangeSampleTime$ = new BehaviorSubject(200);
        this._includeInBounds$ = new BehaviorSubject(new Map());
        this.bounds$ = from(loader.load()).pipe(flatMap(function () { return _this._includeInBounds$; }), sample(this._boundsChangeSampleTime$.pipe(switchMap(function (time) { return timer(0, time); }))), map(function (includeInBounds) { return _this._generateBounds(includeInBounds); }), shareReplay(1));
    }
    FitBoundsService.prototype._generateBounds = function (includeInBounds) {
        var bounds = new google.maps.LatLngBounds();
        includeInBounds.forEach(function (b) { return bounds.extend(b); });
        return bounds;
    };
    FitBoundsService.prototype.addToBounds = function (latLng) {
        var id = this._createIdentifier(latLng);
        if (this._includeInBounds$.value.has(id)) {
            return;
        }
        var map = this._includeInBounds$.value;
        map.set(id, latLng);
        this._includeInBounds$.next(map);
    };
    FitBoundsService.prototype.removeFromBounds = function (latLng) {
        var map = this._includeInBounds$.value;
        map.delete(this._createIdentifier(latLng));
        this._includeInBounds$.next(map);
    };
    FitBoundsService.prototype.changeFitBoundsChangeSampleTime = function (timeMs) {
        this._boundsChangeSampleTime$.next(timeMs);
    };
    FitBoundsService.prototype.getBounds$ = function () {
        return this.bounds$;
    };
    FitBoundsService.prototype._createIdentifier = function (latLng) {
        return latLng.lat + "+" + latLng.lng;
    };
    FitBoundsService.decorators = [
        { type: Injectable },
    ];
    /** @nocollapse */
    FitBoundsService.ctorParameters = function () { return [
        { type: MapsAPILoader, },
    ]; };
    return FitBoundsService;
}());
export { FitBoundsService };
//# sourceMappingURL=fit-bounds.js.map


// WEBPACK FOOTER //
// ./node_modules/@agm/core/services/fit-bounds.js.pre-build-optimizer.js

@agm/[email protected] does work fine with Angular 6.0.0 however.

teddest avatar Sep 28 '18 16:09 teddest

We also experienced the same error. Previously had "@agm/core": "^1.0.0-beta.2" which was installing "@agm/[email protected]" but recently has been installing "@agm/[email protected]". Which broke our site. Changing the package.json to specify exact version is our workaround for now. "@agm/core": "1.0.0-beta.3".

monigala avatar Oct 04 '18 19:10 monigala

Since you are creating Angular: 5 application :

Angular: 5.2.11

RxJS 5.x package is installed with it.

But starting from @agm/[email protected] the library has a dependency to RxJS 6.x, that's the reason why this error occurs.

So, the solution would to update RxJS from from 5.x to 6.x:

npm uninstall rxjs
npm install rxjs@6 rxjs-compat@6 --save

vgrem avatar Oct 10 '18 15:10 vgrem

@vgrem I was facing the same issue. Yours reply worked for me. Thanx much

Suhailattatras avatar Oct 12 '18 06:10 Suhailattatras

@vgrem work for me

AhmadSayadi avatar Oct 18 '18 04:10 AhmadSayadi

@vgrem Thank you, work for me.

marvinajcuc avatar Oct 26 '18 05:10 marvinajcuc

Try this. 'npm i agm-core'. It works fine for me

DaveatCor avatar Dec 01 '18 04:12 DaveatCor

@vgrem Thanks !!!

AbrahamGarcia240 avatar Jan 02 '19 01:01 AbrahamGarcia240

Thank you @vgrem your solution is great, very fine

npm uninstall rxjs
npm install rxjs@6 rxjs-compat@6 --save

it's work very wel for me.

joker7blue avatar Jan 14 '19 16:01 joker7blue

Since you are creating Angular: 5 application :

Angular: 5.2.11

RxJS 5.x package is installed with it.

But starting from @agm/[email protected] the library has a dependency to RxJS 6.x, that's the reason why this error occurs.

So, the solution would to update RxJS from from 5.x to 6.x:

npm uninstall rxjs
npm install rxjs@6 rxjs-compat@6 --save

Thank you !!!

pierrephilippe avatar Jan 25 '19 11:01 pierrephilippe

Didn't work for me. I installed rxjs@6 and rxjs-compat@6, but now I have more errors in console:

ERROR in node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected.
node_modules/rxjs/internal/types.d.ts(81,74): error TS1005: ';' expected.
node_modules/rxjs/internal/types.d.ts(81,77): error TS1109: Expression expected.

I have @agm/core 1.0.0-beta.5 and @angular/core 5.2.11

Help!

GioPetrucci avatar Feb 01 '19 17:02 GioPetrucci

thank you sebastian, very good.

Le ven. 1 févr. 2019 à 18:44, GioPetrucci [email protected] a écrit :

Didn't work for me. I installed rxjs@6 and rxjs-compat@6, but now I have more errors in console:

ERROR in node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected. node_modules/rxjs/internal/types.d.ts(81,74): error TS1005: ';' expected. node_modules/rxjs/internal/types.d.ts(81,77): error TS1109: Expression expected.

I have @agm/core 1.0.0-beta.5 and @angular/core 5.2.11

Help!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/SebastianM/angular-google-maps/issues/1511#issuecomment-459805906, or mute the thread https://github.com/notifications/unsubscribe-auth/AsaAFdzd4L72QRQR6xX82u9UTBqZi_TTks5vJHzzgaJpZM4W8OOM .

joker7blue avatar Feb 02 '19 08:02 joker7blue

Since you are creating Angular: 5 application :

Angular: 5.2.11

RxJS 5.x package is installed with it.

But starting from @agm/[email protected] http://url/ the library has a dependency to RxJS 6.x, that's the reason why this error occurs.

So, the solution would to update RxJS from from 5.x to 6.x https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md :

npm uninstall rxjs npm install rxjs@6 rxjs-compat@6 --save

Le sam. 2 févr. 2019 à 09:24, Fouejio Georges [email protected] a écrit :

thank you sebastian, very good.

Le ven. 1 févr. 2019 à 18:44, GioPetrucci [email protected] a écrit :

Didn't work for me. I installed rxjs@6 and rxjs-compat@6, but now I have more errors in console:

ERROR in node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected. node_modules/rxjs/internal/types.d.ts(81,74): error TS1005: ';' expected. node_modules/rxjs/internal/types.d.ts(81,77): error TS1109: Expression expected.

I have @agm/core 1.0.0-beta.5 and @angular/core 5.2.11

Help!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/SebastianM/angular-google-maps/issues/1511#issuecomment-459805906, or mute the thread https://github.com/notifications/unsubscribe-auth/AsaAFdzd4L72QRQR6xX82u9UTBqZi_TTks5vJHzzgaJpZM4W8OOM .

joker7blue avatar Feb 02 '19 08:02 joker7blue

Didn't work for me. I installed rxjs@6 and rxjs-compat@6, but now I have more errors in console:

ERROR in node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected.
node_modules/rxjs/internal/types.d.ts(81,74): error TS1005: ';' expected.
node_modules/rxjs/internal/types.d.ts(81,77): error TS1109: Expression expected.

I have @agm/core 1.0.0-beta.5 and @angular/core 5.2.11

Help!

Same here!

alessandrosilva avatar Feb 08 '19 12:02 alessandrosilva

may be, you have a syntax error. check your code very well

RROR in node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected.

i'm seeing that << ';' expected. >>, check your syntax because Angular like soft code.

if the Error persist, tell me again

Le ven. 8 févr. 2019 à 13:18, Alessandro Oliveira Silva < [email protected]> a écrit :

Didn't work for me. I installed rxjs@6 and rxjs-compat@6, but now I have more errors in console:

ERROR in node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected. node_modules/rxjs/internal/types.d.ts(81,74): error TS1005: ';' expected. node_modules/rxjs/internal/types.d.ts(81,77): error TS1109: Expression expected.

I have @agm/core 1.0.0-beta.5 and @angular/core 5.2.11

Help!

Same here!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/SebastianM/angular-google-maps/issues/1511#issuecomment-461785390, or mute the thread https://github.com/notifications/unsubscribe-auth/AsaAFcrrjl40kD5DQkAsAU1hciR5kbjIks5vLWsLgaJpZM4W8OOM .

joker7blue avatar Feb 09 '19 06:02 joker7blue

@joker7blue any workaround?

gtzinos avatar Feb 26 '19 10:02 gtzinos

I think you used the dependency in package.json like this : "@agm/core": "^1.0.0-beta.2" When you use ^ ... npm will optimize your dependency, trying to keep the package up-to-date until this package is compatible with the others... but in this case the npm thinks wrong

I used this syntax and the npm installed the beta.5 .... You can check this if u search the agm folder in node_modules and open the agm's package.json.. there is a "version" key for it.

If I delete the ^ before the version number I force the npm to use this version and this solved my problem.

I hope it helps.

zsoltuveges avatar Feb 27 '19 13:02 zsoltuveges

Yes i used "@agm/core": "1.0.0-beta.3" and now it works.

gtzinos avatar Feb 28 '19 10:02 gtzinos

Work for me also. Thank you.

mtimoleon avatar May 03 '19 19:05 mtimoleon