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

(index):72 Uncaught ReferenceError: $ is not defined #185

Closed
tanyewei opened this issue Jul 4, 2017 · 4 comments
Closed

(index):72 Uncaught ReferenceError: $ is not defined #185

tanyewei opened this issue Jul 4, 2017 · 4 comments

Comments

@tanyewei
Copy link

tanyewei commented Jul 4, 2017

new webpack.ProvidePlugin({ $: 'jquery',
                            jQuery: 'jquery' }),
@wonderbred
Copy link

I was getting the same error using the eonasdan-bootstrap-datetimepicker widget.

I tried several things, including adding the last two lines here to the ProvidePlugin section of webpack.config.js:

    new webpack.ProvidePlugin({ $: 'jquery',
                                jQuery: 'jquery',
                                'window.$': 'jquery',
                                'window.jQuery': 'jquery' }),

The only thing that actually worked, however, was changing require('jquery'); in main.js to this:

window.$ = window.jQuery = require('jquery');

This might not be ideal, though. Does anyone have a better solution?

@dylanjnz
Copy link

I was able to get this resolved by adding the expose-loader, and specifying this as the loader in the exports:

npm i expose-loader -s

And then in

module: { 
  loaders { 
    ... 
    { test: require.resolve('jquery'), loaders: ['expose-loader?$', 'expose-loader?jQuery'] },

@wonderbred
Copy link

This worked for me and seems like a much cleaner solution.

Thanks, @dylanjnz !

@sloria
Copy link
Collaborator

sloria commented Mar 9, 2019

Closing, as this issue is stale. Feel free to reopen or comment if there's still an issue.

@sloria sloria closed this as completed Mar 9, 2019
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

4 participants