简体   繁体   English

使用 webpack 获取“未捕获的类型错误:$(...).tablesorter is not a function”

[英]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.

相关问题 未捕获的TypeError:jQuery(...)。tablesorter不是一个函数 - Uncaught TypeError: jQuery(…).tablesorter is not a function 在Webpack项目中获取“未捕获的TypeError:path.parse不是函数” - Getting “Uncaught TypeError: path.parse is not a function” in Webpack project Uncaught TypeError: Object(...) is not a function 当与 WebPack 4 捆绑时 - Uncaught TypeError: Object(...) is not a function when bundling with WebPack 4 未捕获的类型错误:__webpack_require__.r 不是函数 - Uncaught TypeError: __webpack_require__.r is not a function 未捕获的类型错误:__webpack_require__.e 不是 function - Uncaught TypeError: __webpack_require__.e is not a function 未捕获的类型错误:__webpack_require__(...).context 不是 function - Uncaught TypeError: __webpack_require__(...).context is not a function (Webpack) Uncaught TypeError: Swal.mixin is not a function - (Webpack) Uncaught TypeError: Swal.mixin is not a function 获取“未捕获的TypeError:$(...)。timeago不是函数” - Getting 'Uncaught TypeError: $(…).timeago is not a function' 获取“未捕获的TypeError:$(...)。dialog不是函数” - Getting “Uncaught TypeError: $(…).dialog is not a function” "通过使用超时和回调获取“未捕获的 TypeError:回调不是函数”" - Getting "Uncaught TypeError: callback is not a function" from using timeout with a callback
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM