Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-128513

Importing javascript library to qml doesn't allow to access modules exports

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.7.1
    • None

    Description

      Hi, I want to preface this by saying that we are not knowledgeable with javascript. We want to use a javascript library that is self contained in single javascript file without any dependencies. So we ended up importing it from qrc like this:

      CMakeLists.txt:

      qt_add_qml_module(
          ...
          QML_FILES
              dagre.js
          ...
      )
      

      main.qml:

      import "qrc:/dagre.js" as Dagre
      

      It seems to import this javascript file without parsing errors, but we can't access the module.exports provided by the library, for example we tried code from their example and we get the following error:

      var g = new Dagre.graphlib.Graph();
      

      error:

      main.qml: TypeError: Cannot read property 'Graph' of undefined 
      

      I'm attaching also the dagre.js, where graphlib export seems to happen in dagre.js:80, but we can't access it from qml.

      Can you check what we could be doing wrong in this process?

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            friendnick Mykola Vankovych
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes