smpallen99

smpallen99

And I continue to struggle with brunch…

I’m trying use the npm version of adminlte bootstrap template. I have the css finally working, but now I’m trying to get the JS working. I’m seeing the following JS console error in my browser:

jquery.js:3850 jQuery.Deferred exception: $(...).DataTable is not a function TypeError: $(...).DataTable is not a function
    at HTMLDocument.<anonymous> (http://localhost:4000/admin/countries:3:28)
    at mightThrow (http://localhost:4000/js/app.js:3743:29)
    at process (http://localhost:4000/js/app.js:3811:12) undefined
jQuery.Deferred.exceptionHook @ jquery.js:3850
process @ jquery.js:3646
getDocumentSelection.js:51 Trying to get configured shortcut
getDocumentSelection.js:47 (2) ["Init Response", undefined]
jquery.js:3859 Uncaught TypeError: $(...).DataTable is not a function
    at HTMLDocument.<anonymous> (countries:3)
    at mightThrow (jquery.js:3574)
    at process (jquery.js:3642)
(anonymous) @ countries:3
mightThrow @ jquery.js:3574
process @ jquery.js:3642

Here is my brunch-config.js file:

exports.config = {
  // See http://brunch.io/#documentation for docs.
  files: {
    javascripts: {
      joinTo: {
        "js/app.js": /^(web\/static\/js)|(node_modules)/,
        // "js/vendor.js": /^(web\/static\/vendor\/js)/
      },
      order: {
        before: [
        ]
      }
    },
    stylesheets: {
      joinTo: "css/app.css"
    },
    templates: {
      joinTo: "js/app.js"
    }
  },

  conventions: {
    assets: /^(web\/static\/assets)/
  },

  // Phoenix paths configuration
  paths: {
    // Dependencies and current project directories to watch
    watched: [
      "web/static",
      "test/static"
    ],
    // Where to compile files to
    public: "priv/static"
  },
  // Configure your plugins
  plugins: {
    babel: {
      // Do not use ES6 compiler in vendor code
      ignore: [/web\/static\/vendor/]
    }
  },
  modules: {
    autoRequire: {
      "js/app.js": ["web/static/js/app"]
    }
  },

  npm: {
    styles: { "admin-lte": [
      "bootstrap/bootstrap.css",
      "bootstrap/bootstrap-theme.css",
      "dist/css/AdminLTE.css", 
      "dist/css/skins/_all-skins.css",
      ] },
    enabled: true,
    globals: {
      $: 'jquery',
      JQuery: 'jquery'
    }
  }
};

and here is my web/static/js/app.js file:

import "phoenix_html"

require('jquery')
require('admin-lte')

Questions:

  1. How to I resolve the jQuery error?
  2. How do I include some of the plugins from the admin-lte package?
  3. Any suggestions on how I really learn brunch. I’m tired of the struggle I face everytime I try to do sometihng, especially with npm packages.

Showing Posts 1 to 10

OvermindDL1

OvermindDL1

Where is this DataTable on $()'s return being defined?

kokolegorille

kokolegorille

Maybe You can try to load jquery after admin-lte.

It might not be relevant at all, but sometimes loading order with jquery is important.

smpallen99

smpallen99 OP

@OvermindDL1 Datatable is under node_modules/admin-lte/plugins/datatables. I presume I need to require it, presumablely in app.js, but now sure how since its bundled inside admin-lte

OvermindDL1

OvermindDL1

How is it bundled in ‘admin-lte’? Is admin-lte constructing it on-load or…?

peerreynders

peerreynders

Ok, you probably got this already covered - but I have to ask - is it running a compatible version of jQuery?

The AdminLTE repository cites jQuery 1.11+ - the current version is at 3.2.1 and a lot of the 1.x shenanigans have be deprecated (npm should get the right version, but where is that jQuery exactly coming from and which version is it actually).

(I hit the jackpot once, so it’s unlikely to happen again.)

smpallen99

smpallen99 OP

So, I got past the the JQuery problem, buy using the jquery that is included in admin-lte. Then hit the next problem with on of the bootstrap packages that was looking for jquery (no caps), so a window.jquery = JQuery fixed that. However, I got stuck on another package that I’m not able to resolve.

import "phoenix_html"

// import JQuery from'jquery'
// var $ = JQuery
// import JQuery from 'admin-lte/plugins/jQuery/jquery-2.2.3.min.js'
// import BootStrap from 'admin-lte/bootstrap/js/bootstrap.min.js'
// require('admin-lte/plugins/jQuery/jquery-2.2.3.min.js')
require('jquery')
console.log("jquery", $('head'), JQuery.fn)
window.jQuery = JQuery
window.jquery = JQuery
// require('admin-lte/bootstrap/js/bootstrap.min.js')
require('admin-lte/bootstrap/js/bootstrap.min.js')
require('admin-lte/plugins/datatables/jquery.dataTables.js')
// window.datatables = datatables
require('admin-lte/plugins/datatables/dataTables.bootstrap.js')
// require('admin-lte/dist/js/app.min.js')
// require('admin-lte/dist/js/demo.js')

gives me the error

jquery [head, prevObject: n.fn.init(1), context: document, selector: "head"] [jquery: "2.2.3", selector: "", constructor: function, toArray: function, get: function…]
countries:3 Uncaught TypeError: $(...).DataTable is not a function
    at HTMLDocument.<anonymous> (countries:3)
    at i (jquery-2.2.3.min.js:6)
    at Object.fireWith [as resolveWith] (jquery-2.2.3.min.js:6)
    at Function.ready (jquery-2.2.3.min.js:6)
    at HTMLDocument.J (jquery-2.2.3.min.js:6)

I’m ready to give up. I’m going to pull the files into my static/vendor folder, specify each individual file in my brunch file and put each individual file into the head of my layout template.

Using npm to pull in packages is a nice idea, but I constantly waist hours trying to get brunch to configured. This is absolutely ridiculous. I almost ready to give up on brunch and learn another solution like webpack.

peerreynders

peerreynders

Just a shot in the dark here - the adminLTE example uses “good ol’” script tags - you are using require - could that interfere with the plugin being able to patch itself into jQuery? (In my experience often jQuery and “modern JavaScript” don’t work all that seamlessly - which is why for the time being I avoid jQuery and anything that depends on it).

Background: How to use RequireJs with jQuery

PS: You may need to add the plugin in brunch-config.ls under npm.static.

brunch-config npm

smpallen99

smpallen99 OP

@perreynders Do you know of a good free admin template that that does not use jQuery? I would love to ditch jQuery, but I have not found anything to give lots of admin UI features. There is a port of admin-lte in Vue. Although it looks pretty good, I don’t believe the port is complete.

smpallen99

smpallen99 OP

static is a good idea. I noticed that the other day, but forgot to try it. I’ll give it a shot.

peerreynders

peerreynders

Can’t endorse anything but I came across this today: Vue admin - most templates use bootstrap 3 (modern incarnation of jQuery-syndrome?) but this uses Bulma which I haven’t come across before.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews