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

"Cannot read property 'fn' of undefined" with webpack #131

Open
bovender opened this issue Mar 31, 2020 · 1 comment
Open

"Cannot read property 'fn' of undefined" with webpack #131

bovender opened this issue Mar 31, 2020 · 1 comment

Comments

@bovender
Copy link

In the past I used Garlic.js with great success, but now that I use webpack to compile my assets, I get this error in the browser console:

garlic.min.js:145 Uncaught TypeError: Cannot read property 'fn' of undefined
    at garlic.min.js:145
    at Object../node_modules/garlicjs/dist/garlic.min.js (garlic.min.js:197)
    at __webpack_require__ (bootstrap:19)
    at Module.<anonymous> (application.js:17)
    at Module../app/javascript/packs/application.js (application.js:32)
    at __webpack_require__ (bootstrap:19)
    at bootstrap:83
    at bootstrap:83
(anonymous) @ garlic.min.js:145
./node_modules/garlicjs/dist/garlic.min.js @ garlic.min.js:197
__webpack_require__ @ bootstrap:19
(anonymous) @ application.js:17
./app/javascript/packs/application.js @ application.js:32
__webpack_require__ @ bootstrap:19
(anonymous) @ bootstrap:83
(anonymous) @ bootstrap:83

My entry point contains this:

require('garlicjs')

And it does not matter whether I change this to:

import 'garlicjs'

I must admit that I am not very good at all at JavaScript, so I would not be surprised if the solution is really simple?

@nathanhennig
Copy link

It's probably too late for this to be helpful to you, but for anyone who finds this issue like I did, here's my solution. I'm using Rails with webpack. In my config/webpack/environment.js file I had:

const webpack = require('webpack')
environment.plugins.prepend('Provide',
  new webpack.ProvidePlugin({
    $: 'jquery',
    jQuery: 'jquery'
  })
)

The problem was fixed by adding 'window.jQuery': 'jquery'.

const webpack = require('webpack')
environment.plugins.prepend('Provide',
  new webpack.ProvidePlugin({
    $: 'jquery',
    jQuery: 'jquery',
    'window.jQuery': 'jquery' // added here
  })
)

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

No branches or pull requests

2 participants