Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack problem #979

Closed
variable opened this issue Sep 9, 2015 · 23 comments
Closed

Webpack problem #979

variable opened this issue Sep 9, 2015 · 23 comments

Comments

@variable
Copy link

variable commented Sep 9, 2015

This is similar to the other issue desandro/masonry#679, I tried your solution but still didn't work.


ERROR in /Users/jameslin/projects/nzpg/~/isotope-layout/js/isotope.js
Module not found: Error: Cannot resolve module 'get-size/get-size' in /Users/jameslin/projects/nzpg/node_modules/isotope-layout/js
 @ /Users/jameslin/projects/nzpg/~/isotope-layout/js/isotope.js 17:4-31:8

ERROR in /Users/jameslin/projects/nzpg/~/isotope-layout/js/isotope.js
Module not found: Error: Cannot resolve module 'matches-selector/matches-selector' in /Users/jameslin/projects/nzpg/node_modules/isotope-layout/js
 @ /Users/jameslin/projects/nzpg/~/isotope-layout/js/isotope.js 17:4-31:8

ERROR in /Users/jameslin/projects/nzpg/~/isotope-layout/js/isotope.js
Module not found: Error: Cannot resolve module 'fizzy-ui-utils/utils' in /Users/jameslin/projects/nzpg/node_modules/isotope-layout/js
 @ /Users/jameslin/projects/nzpg/~/isotope-layout/js/isotope.js 17:4-31:8

ERROR in /Users/jameslin/projects/nzpg/~/isotope-layout/js/isotope.js
Module not found: Error: Cannot resolve module 'outlayer/outlayer' in /Users/jameslin/projects/nzpg/node_modules/isotope-layout/js
 @ /Users/jameslin/projects/nzpg/~/isotope-layout/js/isotope.js 17:4-31:8

ERROR in /Users/jameslin/projects/nzpg/~/alt/lib/index.js
Module not found: Error: Cannot resolve module 'flux' in /Users/jameslin/projects/nzpg/node_modules/alt/lib
 @ /Users/jameslin/projects/nzpg/~/alt/lib/index.js 23:12-27

ERROR in /Users/jameslin/projects/nzpg/~/isotope-layout/js/layout-mode.js
Module not found: Error: Cannot resolve module 'get-size/get-size' in /Users/jameslin/projects/nzpg/node_modules/isotope-layout/js
 @ /Users/jameslin/projects/nzpg/~/isotope-layout/js/layout-mode.js 11:4-15:15

ERROR in /Users/jameslin/projects/nzpg/~/isotope-layout/js/layout-mode.js
Module not found: Error: Cannot resolve module 'outlayer/outlayer' in /Users/jameslin/projects/nzpg/node_modules/isotope-layout/js
 @ /Users/jameslin/projects/nzpg/~/isotope-layout/js/layout-mode.js 11:4-15:15

ERROR in /Users/jameslin/projects/nzpg/~/isotope-layout/js/item.js
Module not found: Error: Cannot resolve module 'outlayer/outlayer' in /Users/jameslin/projects/nzpg/node_modules/isotope-layout/js
 @ /Users/jameslin/projects/nzpg/~/isotope-layout/js/item.js 10:4-13:15

ERROR in /Users/jameslin/projects/nzpg/~/isotope-layout/js/layout-modes/masonry.js
Module not found: Error: Cannot resolve module 'masonry/masonry' in /Users/jameslin/projects/nzpg/node_modules/isotope-layout/js/layout-modes
 @ /Users/jameslin/projects/nzpg/~/isotope-layout/js/layout-modes/masonry.js 12:4-16:15

ERROR in /Users/jameslin/projects/nzpg/~/alt/lib/store/StoreMixin.js
Module not found: Error: Cannot resolve module 'transmitter' in /Users/jameslin/projects/nzpg/node_modules/alt/lib/store
 @ /Users/jameslin/projects/nzpg/~/alt/lib/store/StoreMixin.js 11:19-41

ERROR in /Users/jameslin/projects/nzpg/~/alt/lib/store/AltStore.js
Module not found: Error: Cannot resolve module 'transmitter' in /Users/jameslin/projects/nzpg/node_modules/alt/lib/store
 @ /Users/jameslin/projects/nzpg/~/alt/lib/store/AltStore.js 19:19-41
desandro added a commit to metafizzy/isotope-docs that referenced this issue Sep 15, 2015
@desandro
Copy link
Member

See the Webpack instructions for Isotope


Install Isotope and imports-loader with npm.

npm install isotope-layout
npm install imports-loader

In your config file, webpack.config.js, use the imports loader to disable define and set window for isotope-layout modules.

// npm v0.x
module.exports = {
  module: {
    loaders: [
      {
        test: /isotope-layout/,
        loader: 'imports?define=>false&this=>window'
      }
    ]
  }
};
// npm >= v3
module.exports = {
  module: {
    loaders: [
      {
        test: /isotope\-|fizzy\-ui\-utils|desandro\-|masonry|outlayer|get\-size|doc\-ready|eventie|eventemitter/,
        loader: 'imports?define=>false&this=>window'
      }
    ]
  }
};

You can then require('isotope-layout').

// main.js
var Isotope = require('isotope-layout');

var iso = new Isotope( '.grid', {
  // options...
});

Run webpack.

webpack main.js bundle.js

This hack is required because of an issue with how Webpack loads dependencies. +1 webpack/webpack#883 to help get this issue addressed.

@variable
Copy link
Author

That's pretty much what I have tried, this is my webpack config.


var staticpath = __dirname + '/nzpg/static';
var webpack = require("webpack");
module.exports = {
  context: staticpath + '/js',
  entry: {
      lib: [
        './lib/common/jquery.js',
        './lib/common/isotope.js',
        './lib/common/functions.js',
        './lib/common/alt.js',
        './lib/comments/comment_box.js',
        './lib/comments/comment_box.jsx',
        './lib/likes/stores.js',
        './lib/likes/actions.js',
        './lib/likes/likes.js',
        './lib/likes/likes.jsx',
        './lib/votes/votes.js',
        './lib/votes/votes.jsx',
        './lib/competitions/stores.js',
        './lib/competitions/actions.js',
        './lib/competitions/entries.jsx',
        './lib/competitions/entries.js',
        './lib/common/controls.js',
      ],
      project: "./project.js",
      competitions: ["./competitions/competitions.js", "./competitions/competition_form.js"],
      photos: "./photos/photos.js",
  },
  output: {
    filename: "[name].js",
    path: staticpath + '/js_built',
  },
  plugins: [ new webpack.optimize.CommonsChunkPlugin('lib', 'lib.js') ],
  resolve: {
    root: staticpath + '/js',
    modulesDirectories: [__dirname+'/node_modules'],
    extensions: ['', '.js', '.jsx']
  },
  module: {
    loaders: [
      {
        test: /isotope-layout/,
        loader: 'imports?define=>false&this=>window'
        //test: /(isotope-layout|masonry|outlayer|item|get-size|fizzy-ui-utils\/utils)\.js$/,
        //loader: 'imports?define=>false'
      },
      {
        test: /\.js.*$/,
        exclude: /node_modules/,
        loaders: ["babel-loader"],
      },
    ],
  },
}

@axelboc
Copy link

axelboc commented Oct 13, 2015

Same issue here. The problem seems to be coming from the latest version of NPM. I don't get the issue with NPM v2.11.3 (the version that comes with Node v0.12.7), but I do with NPM v3.3.6.

@brikou
Copy link

brikou commented Oct 20, 2015

I confirm isotope is broken with npm3

npm install -g npm@3
npm install isotope-layout
# lol

@desandro
Copy link
Member

With npm v3, try listing all isotope dependencies, this code has been added to my comment above

module.exports = {
  module: {
    loaders: [
      {
        test: /isotope\-|fizzy\-ui\-utils|desandro\-|masonry|outlayer|get\-size|doc\-ready|eventie|eventemitter/,
        loader: 'imports?define=>false&this=>window'
      }
    ]
  }
};

@Spittal
Copy link

Spittal commented Dec 2, 2015

I can confirm that @desandro method does work, however... This should be fixed in the core library to work with webpack

desandro added a commit to metafizzy/isotope-docs that referenced this issue Dec 2, 2015
@lbineau
Copy link

lbineau commented Jan 5, 2016

Hi,

Thank you for the quickfix. I got the same problem but for 'isotope-packery'.

var IsotopePackery = require('isotope-packery');
ERROR in ./~/packery/js/packery.js
Module not found: Error: Cannot resolve module 'classie/classie' in /Users/lbineau/Sites/design-implemenation/node_modules/packery/js
 @ ./~/packery/js/packery.js 17:4-25:15

ERROR in ./~/packery/js/item.js
Module not found: Error: Cannot resolve module 'get-style-property/get-style-property' in /Users/lbineau/Sites/design-implemenation/node_modules/packery/js
 @ ./~/packery/js/item.js 11:4-16:15

I tried to modify the following but the error remains:

loaders: [
  {
    test: /isotope\-|fizzy\-ui\-utils|desandro\-|masonry|outlayer|get\-size|doc\-ready|eventie|eventemitter|classie|get\-style\-property/,
    loader: 'imports?define=>false&this=>window'
  }
]

@desandro
Copy link
Member

desandro commented Jan 5, 2016

@lbineau Try adding packery to the test RegEx

loaders: [
  {
    test: /isotope\-|fizzy\-ui\-utils|desandro\-|masonry|outlayer|get\-size|doc\-ready|eventie|eventemitter|classie|get\-style\-property|packery/,
    loader: 'imports?define=>false&this=>window'
  }
]

@lbineau
Copy link

lbineau commented Jan 5, 2016

I've missed this one it's working now, thank you for the fast reply !

@dstarosta
Copy link

The solution does not work for me using NPM 3.8.1. I have tried every loader suggestion. I use babel-loader, if that makes a difference.

The errors order changes when I added the loader. The errors are still the same. The first error changes from

ERROR in ..//isotope-layout/js/isotope.js
Module not found: Error: Cannot resolve module 'get-size/get-size' in D:\Development\SomeApp\node_modules\isotope-layout\js
@ ../
/isotope-layout/js/isotope.js 17:4-31:8

to

ERROR in ..//isotope-layout/js/isotope.js
Module not found: Error: Cannot resolve module 'outlayer' in D:\Development\SomeApp\node_modules\isotope-layout\js
@ ../
/isotope-layout/js/isotope.js 40:6-25

@dstarosta
Copy link

I figured the problem out. If you are using babel loader, make sure to include the "transform-runtime" plugin to the "query" property of the loader.

loaders: [{
  test: /\.js$/,
  exclude: /(node_module)/,
  loader: "babel",
  query: {
    plugins: ["transform-runtime", "transform-decorators-legacy"],
    presets: ["es2015", "stage-1"]
  }
}]

@desandro
Copy link
Member

Isotope v3 has been released with simplified Webpack integration

In your config file, webpack.config.js, add these resolve aliases.

module.exports = {
  resolve: {
    alias: {
      'masonry': 'masonry-layout',
      'isotope': 'isotope-layout'
    }
  }
};

@nathanchase
Copy link

@desandro How would one go about integrating 'isotope-packery' alongside this new simplified Webpack integration?

I've got the following in my package.json:
"isotope-layout": "^3.0.0",
"isotope-packery": "^2.0.0",
"masonry-layout": "^4.1.0",

and then:
var Isotope = require('isotope-layout');
in my .js

how do I avoid this error:

isotope.js:447 - Uncaught Error: No layout mode: packery

?

@nathanchase
Copy link

More feedback on the specific error:

ERROR in ./~/isotope-packery/packery-mode.js Module not found: Error: Cannot resolve module 'isotope-packery/js/layout-mode'

@desandro
Copy link
Member

@nathanchase Looks like you need to require isotope-packery. I was able to make it work with the simplified config above. My .js:

var Isotope = require('isotope-layout');
require('isotope-packery');

new Isotope('.grid', {
  layoutMode: 'packery'
});

@nathanchase
Copy link

I've got
var Isotope = require('isotope-layout'); require('isotope-packery');

and still get isotope.js:447 Uncaught Error: No layout mode: packery

If I add a console.log(packery);, I get Unhandled rejection ReferenceError: packery is not defined

@nathanchase
Copy link

nathanchase commented May 17, 2016

Maybe this will help. Here's my relevant part of my webpack.config.js:

alias: {
            'imagesLoaded': 'imagesloaded',
            'flickity': 'flickity',
            'isotope': 'isotope-layout',
            'masonry': 'masonry-layout',
            'isotope-packery': 'isotope-packery',
            'eventEmitter/EventEmitter': 'wolfy87-eventemitter/EventEmitter',
            'get-style-property': 'desandro-get-style-property',
            'matches-selector': 'desandro-matches-selector',
            'classie': 'desandro-classie'
        }

Flickity works fine. Isotope works fine when in masonry or default mode. It's only when I try to use packery mode that it falis with isotope.js:447 Uncaught Error: No layout mode: packery

@desandro
Copy link
Member

Hmm, try removing 'isotope-packery': 'isotope-packery'. Shouldn't be necessary.

@nathanchase
Copy link

Yeah, tried removing it. Same result. No layout mode: packery

@nathanchase
Copy link

nathanchase commented May 17, 2016

Here's something:

In isotope-layout's package.json, it has a:

"main: "js/isotope.js",

which resolves, because there is a path under isotope-layout to js/isotope.js

BUT

in isotope-packery's package,json, it has:

"main": "js/packery.js", which does NOT resolve, because there's no 'js' folder.

There's just:

node_modules
sandbox
and root files

Could that be the issue?

@nathanchase
Copy link

nathanchase commented May 17, 2016

Here's webpack's build output... it seems to be getting everything for packery, but somehow still isn't available:

[397] ./~/isotope-layout/js/isotope.js 17.3 kB {1} [built]
  [398] ./~/isotope-layout/~/get-size/get-size.js 5.3 kB {1} [built]
  [399] ./~/isotope-layout/~/desandro-matches-selector/matches-selector.js 1.3 kB {1} [built]
  [400] ./~/isotope-layout/~/fizzy-ui-utils/utils.js 5.79 kB {1} [built]
  [401] ./~/isotope-layout/~/outlayer/outlayer.js 22 kB {1} [built]
  [402] ./~/isotope-layout/~/outlayer/~/ev-emitter/ev-emitter.js 2.55 kB {1} [built]
  [403] ./~/isotope-layout/~/outlayer/item.js 14.7 kB {1} [built]
  [404] ./~/isotope-layout/js/layout-mode.js 4.02 kB {1} [built]
  [405] ./~/isotope-layout/js/layout-modes/masonry.js 1.83 kB {1} [built]
  [406] ./~/isotope-layout/~/masonry-layout/masonry.js 6.45 kB {1} [built]
  [407] ./~/isotope-layout/js/layout-modes/fit-rows.js 1.4 kB {1} [built]
  [408] ./~/isotope-layout/js/layout-modes/vertical.js 1.1 kB {1} [built]
  [409] ./~/isotope-layout/js/item.js 1.77 kB {1} [built]
  [410] ./~/isotope-packery/packery-mode.js 2.37 kB {1} [built]
  [411] ./~/isotope-packery/~/isotope-layout/js/layout-mode.js 4.02 kB {1} [built]
  [412] ./~/isotope-packery/~/isotope-layout/~/get-size/get-size.js 5.3 kB {1} [built]
  [413] ./~/isotope-packery/~/isotope-layout/~/outlayer/outlayer.js 22 kB {1} [built]
  [414] ./~/isotope-packery/~/isotope-layout/~/outlayer/~/ev-emitter/ev-emitter.js 2.55 kB {1} [built]
  [415] ./~/isotope-packery/~/isotope-layout/~/fizzy-ui-utils/utils.js 5.79 kB {1} [built]
  [416] ./~/isotope-packery/~/isotope-layout/~/desandro-matches-selector/matches-selector.js 1.3 kB {1} [built]
  [417] ./~/isotope-packery/~/isotope-layout/~/outlayer/item.js 14.7 kB {1} [built]
  [418] ./~/isotope-packery/~/packery/js/packery.js 17.7 kB {1} [built]
  [419] ./~/isotope-packery/~/packery/~/get-size/get-size.js 5.3 kB {1} [built]
  [420] ./~/isotope-packery/~/packery/~/outlayer/outlayer.js 22 kB {1} [built]
  [421] ./~/isotope-packery/~/packery/~/outlayer/~/ev-emitter/ev-emitter.js 2.55 kB {1} [built]
  [422] ./~/isotope-packery/~/packery/~/outlayer/~/fizzy-ui-utils/utils.js 5.79 kB {1} [built]
  [423] ./~/isotope-packery/~/packery/~/outlayer/~/fizzy-ui-utils/~/desandro-matches-selector/matches-selector.js 1.3 kB {1} [built]
  [424] ./~/isotope-packery/~/packery/~/outlayer/item.js 14.7 kB {1} [built]
  [425] ./~/isotope-packery/~/packery/js/rect.js 3.28 kB {1} [built]
  [426] ./~/isotope-packery/~/packery/js/packer.js 4.74 kB {1} [built]
  [427] ./~/isotope-packery/~/packery/js/item.js 3.33 kB {1} [built]

@nathanchase
Copy link

So, I blew out my node_modules folder, let it regrab everything, and now it's fine. Argh! Frustrating!

For reference, my webpack.config.js:

alias: {
            'imagesLoaded': 'imagesloaded',
            'flickity': 'flickity',
            'masonry': 'masonry-layout',
            'isotope': 'isotope-layout',
            'eventEmitter/EventEmitter': 'wolfy87-eventemitter/EventEmitter',
            'get-style-property': 'desandro-get-style-property',
            'matches-selector': 'desandro-matches-selector',
            'classie': 'desandro-classie'
        }

@desandro
Copy link
Member

desandro commented Nov 6, 2016

I'm closing this issue as Webpack use with Isotope has been simplified in v3, see comment above #979 (comment)

If you run into issues with Isotope and Webpack, please open a new issue.

@desandro desandro closed this as completed Nov 6, 2016
@metafizzy metafizzy locked and limited conversation to collaborators Nov 6, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

8 participants