Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
7.0.1
-
None
-
None
Description
If you have a <script> tag in your app which points to a custom JS file called cordova.js, e.g. `myapp/js/cordova.js` then (if this custom <script> tag appears after the <script> tag for Cordova's cordova.js, which lives in the root of the `platforms/<platform>/www` folder) then it causes `findCordovaPath()` to return the path as the path to your custom file, rather than Cordova's file. That then breaks other things, such as the loading of plugins, causing all your plugins to be silently undefined in JS.
As far as I can tell, there's nothing in the documentation to say that you shouldn't have a filed called cordova.js, and it's a perfectly valid thing to do in general (in HTML) and both scripts run. And as it fails silently, there's no way of knowing that this is the problem other than spending hours debugging it to get down to the cause.
I can think of several ways of tackling this:
1. Change `findCordovaPath` to look for the shortest path that points to a cordova.js file (because the auto-generated one lives at the root of your platform build, whereas custom ones will always live in some sub-folder).
2. Add something to do the documentation to make it clear that you shouldn't name any of your own files cordova.js.
3. Both 1 and 2.
4. Raise an error during the build process to catch this problem.
Here's the `findCordovaPath` code for reference:
function findCordovaPath () { var path = null; var scripts = document.getElementsByTagName('script'); var term = '/cordova.js'; for (var n = scripts.length - 1; n > -1; n--) { var src = scripts[n].src.replace(/\?.*$/, ''); // Strip any query param (CB-6007). if (src.indexOf(term) === (src.length - term.length)) { path = src.substring(0, src.length - term.length) + '/'; break; } } return path; }