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

error when using with webpack #22

Open
dev-seahouse opened this issue Jun 22, 2017 · 9 comments
Open

error when using with webpack #22

dev-seahouse opened this issue Jun 22, 2017 · 9 comments
Labels

Comments

@dev-seahouse
Copy link

i got the following error in dev tool and yet it is still working.

app.js?id=06c12ce…:561 Uncaught TypeError: e.removeEventListener is not a function
    at Object.u.drop (app.js?id=06c12ce…:561)
    at Object.u.check (app.js?id=06c12ce…:561)
    at Object.u.render (app.js?id=06c12ce…:561)
    at Object.u.init (app.js?id=06c12ce…:561)
    at Facilis er...:261

What i did:

window.progressively= require(progressively);
progressively.init();
@dev-seahouse
Copy link
Author

;
(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
    define(function () {
     root = window; // <========= this fixed it, the problem seem to be 'root' is not window object for some reason
      return factory(root)
    })
  } else if (typeof exports === 'object') {
    module.exports = factory
  } else {
    root.progressively = factory(root)
  }
})(this, function (root) {
  'use strict'

@thinker3197
Copy link
Owner

This seems to be happening because root is not defined when the factory function is exported. I'll find a workaround soon and post it in this thread.
Till then, you could use webpack's external configuration. Hope that will solve your problem.

@the94air
Copy link
Contributor

the94air commented Oct 21, 2017

@thinker3197 Did you find any solution? I kind of running in the same issue.

@thinker3197
Copy link
Owner

thinker3197 commented Oct 22, 2017

I tried out a few other plugins and this is a common issue when using js/jquery libraries with webpack. This happens, as I stated above because webpack wraps the package in it's own object while bundling thus loosing the access to window object. You can use the above mentioned solution if that helps!

@the94air
Copy link
Contributor

Then.. I guess I will use the CDN version for now. Thanks.

@koishimasato
Copy link

@dev-seahouse

In my environments, this would work. (webpack 3)

in webpack.config.js:

module: {
  rules: [
      ...
      {
        test: /progressively.*\.js$/,
        loader: 'imports-loader?this=>window',
      },
   ],
  },

in js:

import progressively from 'progressively';
progressively.init();

@the94air
Copy link
Contributor

Thanks @koishimasato for sharing the solution. I'll try it out later.

@cgpro
Copy link

cgpro commented Nov 18, 2018

@koishimasato solution doesn't work with webpack 4. Any ideas?

@LockeAG
Copy link

LockeAG commented Dec 25, 2018

;
(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
    define(function () {
     root = window; // <========= this fixed it, the problem seem to be 'root' is not window object for some reason
      return factory(root)
    })
  } else if (typeof exports === 'object') {
    module.exports = factory
  } else {
    root.progressively = factory(root)
  }
})(this, function (root) {
  'use strict'

Yep , this works 👍

import progressively from 'progressively/src/progressively';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants