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

TypeError: element.masonry is not a function

Open Vaibhav-Chavan opened this issue 10 years ago • 18 comments

Error Occurred while including angular-masonry in our App

TypeError: element.masonry is not a function at preLink (http://192.168.1.171:8100/js/directive.js:3965:29) at invokeLinkFn (http://192.168.1.171:8100/lib/ionic/js/ionic.bundle.js:17477:9) at nodeLinkFn (http://192.168.1.171:8100/lib/ionic/js/ionic.bundle.js:16956:11) at compositeLinkFn (http://192.168.1.171:8100/lib/ionic/js/ionic.bundle.js:16368:13) at compositeLinkFn (http://192.168.1.171:8100/lib/ionic/js/ionic.bundle.js:16372:13) at nodeLinkFn (http://192.168.1.171:8100/lib/ionic/js/ionic.bundle.js:16972:24) at compositeLinkFn (http://192.168.1.171:8100/lib/ionic/js/ionic.bundle.js:16368:13) at compositeLinkFn (http://192.168.1.171:8100/lib/ionic/js/ionic.bundle.js:16372:13) at nodeLinkFn (http://192.168.1.171:8100/lib/ionic/js/ionic.bundle.js:16972:24) at compositeLinkFn (http://192.168.1.171:8100/lib/ionic/js/ionic.bundle.js:16368:13)

When we are trying to add jquery library file in index.html before ionic.bundle.js following error occurred....but when we put it down after ionic.bundle.js above error occurred..

ReferenceError: it is not defined at eval (eval at (http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js:2:2533), :1:1) at eval (native) at Function.o.extend.globalEval (http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js:2:2533) at o.fn.extend.domManip (http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js:3:16727) at o.fn.extend.append (http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js:3:14410) at self.appendViewElement (http://192.168.1.171:8100/lib/ionic/js/ionic.bundle.js:52249:14) at Object.switcher.render (http://192.168.1.171:8100/lib/ionic/js/ionic.bundle.js:50449:41) at Object.switcher.init (http://192.168.1.171:8100/lib/ionic/js/ionic.bundle.js:50369:20) at self.render (http://192.168.1.171:8100/lib/ionic/js/ionic.bundle.js:52115:14) at self.register (http://192.168.1.171:8100/lib/ionic/js/ionic.bundle.js:52073:10)

Please help us to resolve this problem... Thanks in advance.

Vaibhav-Chavan avatar Oct 28 '15 12:10 Vaibhav-Chavan

#131 this may help you

LuciferZhang avatar Oct 29 '15 01:10 LuciferZhang

Still facing same issue

ReferenceError: it is not defined at eval (eval at (http://192.168.1.169:8100/lib/angular-masonry/jquery.js:328:5), :1:1) at eval (native) at Function.jQuery.extend.globalEval (http://192.168.1.169:8100/lib/angular-masonry/jquery.js:328:5) at jQuery.fn.extend.domManip (http://192.168.1.169:8100/lib/angular-masonry/jquery.js:5435:16) at jQuery.fn.extend.append (http://192.168.1.169:8100/lib/angular-masonry/jquery.js:5218:15) at self.appendViewElement (http://192.168.1.169:8100/lib/ionic/js/ionic.bundle.js:52249:14) at Object.switcher.render (http://192.168.1.169:8100/lib/ionic/js/ionic.bundle.js:50449:41) at Object.switcher.init (http://192.168.1.169:8100/lib/ionic/js/ionic.bundle.js:50369:20) at self.render (http://192.168.1.169:8100/lib/ionic/js/ionic.bundle.js:52115:14) at self.register (http://192.168.1.169:8100/lib/ionic/js/ionic.bundle.js:52073:10)

Please help

Vaibhav-Chavan avatar Oct 29 '15 07:10 Vaibhav-Chavan

Check the reason over here

RopoMen avatar Nov 10 '15 09:11 RopoMen

Same error in my implementation

juanpasolano avatar Nov 13 '15 23:11 juanpasolano

Same error in my implementation. Dependencies are all in the right order. element.masonry() is not a function.

christrude avatar Dec 29 '15 16:12 christrude

Hello I have a same problem. I'm using Ionic. Is there other way when you use Ionic?

Thanks

Taewa avatar Feb 02 '16 09:02 Taewa

I got it working by adding the following to the overrides section in the bower.json file.

"ev-emitter": {
  "dependencies": {
    "jquery-bridget": "~2.0.0"
  }
},
"outlayer": {
  "main": [
    "item.js",
    "outlayer.js"
  ]
}

JoshuaNovak919 avatar Feb 22 '16 05:02 JoshuaNovak919

the solution @JoshuaNovak919 provided works for me. It only works if jquery-bridget.js is loaded before ev-emitter.js :)

Devqon avatar Mar 04 '16 11:03 Devqon

@JoshuaNovak919 solution works for me as well, thank you!

matheusdavidson avatar Aug 05 '16 00:08 matheusdavidson

If FIXED it including Jquery dependency (jquery/dist/jquery.js) before ionic's bundle file (ionic/js/ionic.bundle.js):

<!-- jquery -->
<script src="lib/jquery/dist/jquery.js"></script>

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>

junit38 avatar Sep 29 '16 14:09 junit38

@JoshuaNovak919 which bower.json? where... please I have this issue too.

victorsosa avatar Dec 02 '16 20:12 victorsosa

@victorsosa The main project bower.json file. It should look something like this:

{
  "name": "MyApp",
  "version": "0.0.0",
  "dependencies": {
    "angular": "^1.4.0",
    "angular-animate": "^1.4.0",
    "angular-cookies": "^1.4.0",
    "angular-resource": "^1.4.0",
    "angular-route": "^1.4.0",
    "angular-sanitize": "^1.4.0",
    "angular-touch": "^1.4.0",
    "angular-material": "master",
    "ngmap": "~1.16.7",
    "jquery": "~2.2.0",
    "ngMask": "angular-mask#~3.0.16",
    "ng-page-title": "~1.1.1",
    "angular-filter": "~0.5.8",
    "angular-masonry": "~0.16.0",
    "lightgallery": "~1.2.14",
    "components-font-awesome": "~4.5.0",
    "animate.css": "~3.5.1"
  },
  "devDependencies": {
    "angular-mocks": "^1.4.0",
    "angular-material": "~1.0.2"
  },
  "appPath": "app",
  "moduleName": "MyApp",
  "overrides": {
    "bootstrap": {
      "main": [
        "less/bootstrap.less",
        "dist/css/bootstrap.css",
        "dist/js/bootstrap.js"
      ]
    },
    "ev-emitter": {
      "dependencies": {
        "jquery-bridget": "~2.0.0"
      }
    },
    "outlayer": {
      "main": [
        "item.js",
        "outlayer.js"
      ]
    }
  }
}

JoshuaNovak919 avatar Dec 07 '16 00:12 JoshuaNovak919

@JoshuaNovak919 thanks

victorsosa avatar Dec 07 '16 13:12 victorsosa

If anyone working with webpack, that's what I had to require in order for it to work:

require('jquery');
require('jquery-bridget');
require('ev-emitter');
require('desandro-matches-selector');
require('fizzy-ui-utils');
require('get-size');
require('masonry-layout');

then in my app:

var app = angular.module('app', [
     (require('angular-masonry'), 'wu.masonry'),
]);

lucas-garcia avatar Mar 29 '17 12:03 lucas-garcia

In case it helps someone...I had to add references to jquery and jquery-bridget for this to work. I didn't see that explicitly documented anywhere. I'm on angular 1.6.2

kevinswartz avatar May 15 '17 20:05 kevinswartz

Is there an example of this working with ES6 style imports?

stevenmccord avatar Sep 26 '17 20:09 stevenmccord

As a clarification, I am trying to do

import 'angular-masonry' and its dependencies but getting this error.

I have tried to split this out into its own vendor file as well to have it load first, but still nothing working just yet.

@lucas-garcia just curious was there anything else you had to do in your webpack config. Thanks!

stevenmccord avatar Sep 27 '17 19:09 stevenmccord

Just figured this out.

It looks like the src file in this directory is much newer than the packaged up lib with npm I just had to alias the angular-masonry to the src and then utilize the import-loader to include masonry and imagesloaded to get this going.

since we are no longer pointing to index.js in the package we have to export wu.masonry manually in the webpack config.

			{
				test: require.resolve('angular-masonry/src/angular-masonry.js'),
				use:{
					loader: 'exports-loader',
					options: '"wu.masonry"'
				}
			},
			{
				test: require.resolve('angular-masonry/src/angular-masonry.js'),
				use: "imports-loader?Masonry=masonry-layout,imagesLoaded=imagesloaded"
			}

alias (not necessarily needed as you could do this in the import as well, but just for ease I do it:

		alias:{
			'angular-masonry': 'angular-masonry/src/angular-masonry'
		},

Then simply do this import:

import wuMasonry from 'angular-masonry'

stevenmccord avatar Sep 28 '17 18:09 stevenmccord