Error while including a third party JS module in my plugin

  • My plugin.json

    	"modules": {
    		"geocomplete.js": "static/lib/geocomplete/jquery.geocomplete.min.js",
    		"tree.js": "static/lib/jstree/jstree.min.js"

    In my map.js file

    requirejs(["tree"], function(tree) {

    When I run, the browser raises this error:

    Uncaught TypeError: Cannot read property 'jstree' of undefined
        at tree.js?v=pl4hsgl3sro:2
        at Object.execCb (require.js:29)
        at w.check (require.js:18)
        at w.<anonymous> (require.js:22)
        at require.js:7
        at require.js:23
        at y (require.js:6)
        at w.emit (require.js:23)
        at w.check (require.js:19)
        at w.enable (require.js:23)

    When I hover over the second line i.e. at tree.js?v=pl4hsgl3sro:2
    it displays this path: localhost:4567/src/modules/tree.js?v=pl4hsgl3sro:2

    When I click on it it displays the contents (minified code) of the tree.min.js in the Sources heading.

    What shall I do, kindly help me resolve this error.

  • Global Moderator

    I suggest changing it to use the unminified files, this way you get the actual code in development. NodeBB automatically minifies all of those files in a production environment anyways. I also suggest you change it to use the same filename as the original: jstree.js instead of tree.js.

    Then you should be able to debug a little easier.

  • Hi Pita

    Ok I understand. Do you mean to say that there is a bug in jstree.js itself and not in our setup?


  • Tried out several ways to solve this errror but none worked. Which version of jQuery is used by the NodeBB currently? Can we use a specific version of jQuery while running NodeBB, if yes, how?

    FYI jsTree requires 1.9.0 or greater.

  • I think I have the same issues as described in this URL:

    But there is no definitive answer over there.

  • This is how I resolved the error:

      shim: {
        jquery: {
          exports: '$'
    requirejs(["jstree"], function(jstree) { ... }

    It may help somebody if she needs to integrate the jstree (popular jQuery plugin) with NodeBB in future.

  • Admin

    Yes, I believe you either need to do this, or alter the jstree.js file itself to change references to jQuery to just use global (as in, don't require jQuery at all)


| |