I'm trying to update our jQuery from 3.6.0
to 3.6.1
within our application using Rails 6.1
with Webpack. We cannot seem to get jQuery loaded after the update. Eg $.fn
or $.get
is undefined.
Here's our configuration
# config/webpack/environment.js
const { environment } = require('@rails/webpacker')
const erb = require('./loaders/erb')
const webpack = require('webpack');
environment.loaders.prepend('erb', erb)
environment.plugins.append('Provide', new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}));
module.exports = environment;
# app/javascript/packs/application.js
import 'core-js/stable'
import 'regenerator-runtime/runtime'
import jQuery from 'jquery'
global.$ = global.jQuery = jQuery
I've tried several things following the documentation on the NPM page but that didn't work yet.
I also created a very basic webpage loading jQuery with the script tag which worked fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.