Cordova modules not loaded: Module cordova-plugin-x-toast.Toast does not exist [solved]

When I add some cordova plugins to my project via npm, the dev build fails to serve the javascript files to the client webview.

I have some plugins listed in my .meteor/cordova-plugins file:

cordova-plugin-file@4.3.3
cordova-plugin-file-transfer@1.6.3
cordova-plugin-x-toast@2.6.0
cordova-plugin-inappbrowser@1.7.1

The first two work fine and I can use their features in my JS. The last two on the other hand, fail to load on my android device. The meteor client makes requests for the JS files that the plugins provide, but the internal server responds with the default meteor bootstrap HTML instead of the JS contents.

I don’t know much about the cordova build process, so this has me stumped. Some details follow.


The working plugins have their JavaScript fetched like this (details from chrome dev tools):

General
  Request URL: http://localhost:12072/plugins/cordova-plugin-file/www/File.js
  Request Method: GET
  Status Code: 200 OK (from disk cache)
  Referrer Policy: no-referrer-when-downgrade
Response Headers
  Client-Via: shouldInterceptRequest
  Content-Length: 2712
  Content-Type: text/javascript

The failing plugins have HTML served to them instead:

General
  Request URL: http://localhost:12072/plugins/cordova-plugin-x-toast/www/Toast.js
  Request Method: GET
  Status Code: 200 OK (from disk cache)
  Referrer Policy: no-referrer-when-downgrade
Response Headers
  Client-Via: shouldInterceptRequest
  Content-Length: 15202
  Content-Type: text/html

The HTML that is served is the same as the initial HTML that is served when you request any non-special path.


As a result of the JS not arriving in the client, we get this stack trace in the console:

Uncaught Error: Module cordova-plugin-x-toast.Toast does not exist.
    at addEntry (cordova.js:1469)
    at Object.exports.clobbers (cordova.js:1479)
    at onScriptLoadingComplete (cordova.js:1893)
    at scriptLoadedCallback (cordova.js:1926)
    at HTMLScriptElement.<anonymous> (cordova.js:1880)

The only place in the built files that I found reference to the working plugins but not the broken plugins was .meteor/local/cordova-build/platforms/android/assets/cdvasset.manifest.

Both the working and the broken plugins have entries for their files in both:

.meteor/local/cordova-build/platforms/android/assets/www/cordova_plugins.js
.meteor/local/cordova-build/platforms/android/platform_www/cordova_plugins.js

and the files for all of the plugins are in both:

.meteor/local/cordova-build/platforms/android/assets/www/plugins/
.meteor/local/cordova-build/platforms/android/platform_www/plugins/

I found the problem! As I moved on from compiling this report to documenting other build bugs, I found the connection between them!

My project suffers from a bug that stops cdvassets.manifest from being generated. Any existing copy of the manifest file is used instead though, so I had forgotten about it, until just now. The manifest file that I found was generated before I added the two new plugins, and so the new plugins weren’t in there. By generating a new manifest file, the JS files for the plugins are now served properly and everything works properly.