imakewebthings / waypoints

Waypoints is a library that makes it easy to execute a function whenever you scroll to an element.
http://imakewebthings.com/waypoints/
10.38k stars 1.33k forks source link

Cannot use waypoints in webpack 4 #598

Closed kytosai closed 4 years ago

kytosai commented 6 years ago

When i import waypoints


import Waypoint from 'waypoints'

new Waypoint({
  element: document.getElementById('pd-block__cart-segment'),
  handler: function() {
    console.log('Scrolled to waypoint!')
    console.log(direction)
  }
})

Console log error

product-detail-page.js:119 Uncaught TypeError: _noframeworkWaypoints2.default is not a constructor
    at Object../src/js/partials/product-detail-page/product-detail-page.js (product-detail-page.js:119)
    at __webpack_require__ (bootstrap:78)
    at Object.11 (product-detail-page.js?v=1533175534:14085)
    at __webpack_require__ (bootstrap:78)
    at checkDeferredModules (bootstrap:45)
    at ./node_modules/babel-loader/lib/index.js!./node_modules/vue-loader/lib/index.js?!./src/js/vue/global/HeaderBlockCateSegment.vue?vue&type=script&lang=js&.Object.defineProperty.value (bootstrap:151)
    at bootstrap:151

Please help me fix it

m-bodmer commented 6 years ago

Same here, I am using "webpack": "^4.16.5"

ccharlton commented 6 years ago

I keep reading this Waypoints library isn't compatible with Webpack. Still true?

ndq11 commented 5 years ago

Change import Waypoint from 'waypoints' to import waypoint from 'waypoints'. As stated in error message - it's not a constructor it's already compiled library, You cannot use it this way. But by attaching script to your page it makes constructor globally accessible on the page.

AdamLemire commented 4 years ago

/ global Waypoint / import 'waypoints/lib/jquery.waypoints.min.js';