Installation Issues - Rails / Yarn / Webpacker

Installation Issues - Rails / Yarn / Webpacker

jasper502jasper502 Posts: 23Questions: 8Answers: 0

Rails 5.x app. Installed jQuery and confirmed that jQuery works.

Installed DT via yarn:

yarn add

added the require:


I added the basic demo and all I get is:

jQuery.Deferred exception: $(...).DataTable is not a function TypeError: $(...).DataTable is not a function
    at HTMLDocument.

Uncaught TypeError: $(...).DataTable is not a function
    at HTMLDocument.<anonymous> (application.js:19)
    at mightThrow (deferred.js:97)
    at process (deferred.js:139)

I added DT to my plugins:

const webpack = require('webpack')
  new webpack.ProvidePlugin({
    $: 'jquery/src/jquery',
    jQuery: 'jquery/src/jquery'
    DataTable: ''

I can get it to work via the CDN:

<script src=""></script>
<link rel="stylesheet" href="">

<script type='text/javascript'>

  $(document).ready(function() {
  } );


I have found this:

At a loss right now.

One clue - if I have the require('')(); AND the CDN at the same time I get these errors:

Uncaught TypeError: Cannot set property '$' of undefined
    at DataTable (jquery.dataTables.js:129)

It makes me think that the require does load DT but it's not registering somewhere.


  • allanallan Posts: 52,250Questions: 1Answers: 7,953 Site admin

    Two possibilities to try:

    require('')( window, jQuery );

    The former is suitable for AMD loading, while the latter is the CommonJS loader.

    If they don't work, can you give me a link to your bundled package?


Sign In or Register to comment.