Details
-
Bug
-
Resolution: Duplicate
-
P2: Important
-
6.5, 6.8, 6.9
-
None
Description
QML import unable to disambiguate module from itself if it contains JavaScript
A module importing modules that import a third module in common, that happens to contain a JavaScript file, will fail to import because the importer is unable to disambiguate the same JavaScript file across the modules attempting to import it. This issue will not happen if the module has only QML files.
Error messages can vary slightly depending on how the modules are setup. Some error messages include:
qrc:/qt/qml/ModuleD/Root.qml:4:1: module "ModuleC" version 1.0 cannot be imported because:
"ModuleA" is ambiguous. Found in qrc:/qt/qml/ModuleA/ and in qrc:/qt/qml/ModuleA/
And:
qrc:/qt/qml/App/Root.qml: module "ModuleC" version 1.0 cannot be imported because:
"ModuleA" is ambiguous. Found in qrc:/qt/qml/ModuleA/ and in qrc:/qt/qml/ModuleA/
qrc:/qt/qml/App/Root.qml: "ModuleA" is ambiguous. Found in qrc:/qt/qml/ModuleA/ and in qrc:/qt/qml/ModuleA/
qrc:/qt/qml/App/Root.qml: Failed to load dependent import "ModuleA" version 255.255
qrc:/qt/qml/App/Root.qml: Failed to load dependencies for module "ModuleC" version 1.0
qrc:/qt/qml/App/Root.qml: Failed to load dependent import "ModuleC" version 1.0
To receive messages regarding the inability to disambiguate, the calls to qt_add_qml_module must have IMPORTS specified. If those aren't specified, the modules will still fail to import, but the explanation will be less clear. JavaScript files will appear as unavailable despite clearly being present in Qt resources. You can use GammaRay to inspect resources if you change an app to not exist the event loop when modules fail to import.
Example of error message when not specifying IMPORTS on qt_add_qml_module:
qrc:/qt/qml/App/Root.qml:14:5: Type TextB unavailable
qrc:/qt/qml/ModuleB/TextB.qml:8:5: Type TextProviderA unavailable
qrc:/qt/qml/ModuleA/TextProviderA.qml:3:1: Script qrc:/qt/qml/ModuleA/Utils.js unavailable
qrc:/qt/qml/ModuleA/Utils.js: No such file or directory
Loaded object: QUrl("qrc:/qt/qml/App/Root.qml")
Loading QML root failed; exiting...
Attached are images and project files further illustrating the issue.
Attachments
Issue Links
- duplicates
-
QTBUG-138391 Deep-nested QML module containing *.mjs file can cause ambiguous import
-
- Closed
-