简体   繁体   English

带有 Webpacker 的 Rails 6.1 使用 jQuery 3.6.1 失败

[英]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.我正在尝试使用带有 Webpack 的 Rails 6.1在我们的应用程序中将 jQuery 从3.6.0更新到3.6.1 We cannot seem to get jQuery loaded after the update.更新后我们似乎无法加载 jQuery。 Eg $.fn or $.get is undefined.例如$.fn$.get是未定义的。

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.我在NPM 页面上的文档之后尝试了几件事,但这还没有奏效。

I also created a very basic webpage loading jQuery with the script tag which worked fine.我还创建了一个非常基本的网页,加载 jQuery 并带有运行良好的脚本标签。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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