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

JS module API doesn't work within JavaScript

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P1: Critical P1: Critical
    • 5.0.0
    • 5.0.0
    • None
    • QtDeclarative sha 0507afe3fc13640fbf7d1a79c6699337b31498fc, Feb 28 2012.

      Running following code gives error "file.js:1: SyntaxError: Unexpected token .".

      .import MyModule 1.0
      
      console.log(MyModule.moduleAPI ? "MyModule is working" : "MyModule is not working")
      

      Importing the same module inside namespace results in error "file.js:3: ReferenceError: Can't find variable: Module":

      .import MyModule 1.0 as Module
      
      console.log(Module.MyModule.moduleAPI ? "MyModule is working" : "MyModule is not working")
      

      Same JS module API import, without initial dot ".", works within QML source file.

      import QtQuick 2.0
      import MyModule 1.0
      
      Item { Component.onCompleted: console.log(MyModule.moduleAPI ? "MyModule is working" : "MyModule is not working") }
      

      MyModule qmldir file contains "MyModule 1.0 MyModule.js". Attached example code as MyModule.tar.gz to reproduce the issue.

        1. MyModule.tar.gz
          0.5 kB
          Joona Petrell
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            mvogt Matthew Vogt (closed Nokia identity) (Inactive)
            jpetrell Joona Petrell
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes