[英]Getting 'Uncaught TypeError: $(...).tablesorter is not a function' using webpack
I'm getting Uncaught TypeError: $(...).tablesorter is not a function
after migrating to Rails 6 with Webpack.在使用 Webpack 迁移到 Rails 6 后,我收到
Uncaught TypeError: $(...).tablesorter is not a function
function。 Here is my environment.js这是我的 environment.js
const { environment } = require('@rails/webpacker')
const webpack = require('webpack')
environment.plugins.prepend('Provide',
new webpack.ProvidePlugin({
$: 'jquery/src/jquery',
jQuery: 'jquery/src/jquery',
tablesorter: 'tablesorter',
bootstrap: 'bootstrap/dist/js/bootstrap',
draggable: 'plain-draggable'
})
)
module.exports = environment
The other plugins associated are working correctly.相关的其他插件工作正常。
I'm not sure exactly why, but it works by doing like this:我不知道究竟是为什么,但它的工作原理是这样的:
import $ from 'jquery'
import 'tablesorter'
$(document).on('turbolinks:load', () => {
$('.tablesorter').tablesorter()
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.