简体   繁体   中英

Rails 6.1 with Webpacker fails with jQuery 3.6.1

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.

①如果本文未解决您的问题,请点击查看与本文相关的问题
②如果本文未解决您的问题,请向程序员专用AI小助手提问

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM