thaliproject / Thali_CordovaPlugin

Thali p2p plugin
MIT License
226 stars 44 forks source link

Fix "Error: Cannot find module './CoordinatedClient" in new test server #1039

Open evabishchevich opened 8 years ago

evabishchevich commented 8 years ago

Error!: Cannot find module './CoordinatedClient' Stack: [{"_fileName":"module.js","_functionName":"$w._oldRes","_lineNumber":"802","_columnNumber":"9","_msg":" at $w._oldRes@module.js:802:9"},{"_fileName":"module.js","_functionName":"$w._resolveFilename","_lineNumber":"1771","_columnNumber":"1","_msg":" at $w._resolveFilename@module.js:1771:1"},{"_fileName":"module.js","_functionName":"$w._load","_lineNumber":"362","_columnNumber":"4","_msg":" at $w._load@module.js:362:4"},{"_fileName":"module.js","_functionName":"$w.prototype.require","_lineNumber":"477","_columnNumber":"8","_msg":" at $w.prototype.require@module.js:477:8"},{"_fileName":"module.js","_functionName":"require","_lineNumber":"495","_columnNumber":"8","_msg":" at require@module.js:495:8"},{"_fileName":"/data/data/com.test.thalitest/files/www/jxcore/lib/CoordinatedTape.js","_functionName":"","_lineNumber":"12","_columnNumber":"25","_msg":" at @/data/data/com.test.thalitest/files/www/jxcore/lib/CoordinatedTape.js:12:25"}] 09-14 18:16:51.282 16527-16612/com.test.thalitest I/jxcore-log: ERROR testUtils: uncaught exception, error: 'Error: Cannot find module './CoordinatedClient'', stack: 'Error: Cannot find module './CoordinatedClient' at $w._oldRes@module.js:802:9 at $w._resolveFilename@module.js:1771:1 at $w._load@module.js:362:4 at $w.prototype.require@module.js:477:8 at require@module.js:495:8 at @/data/data/com.test.thalitest/files/www/jxcore/lib/CoordinatedTape.js:12:25' 09-14 18:16:51.282 16527-16612/com.test.thalitest I/jxcore-log: ERROR testUtils: _TEST_LOGGER:[PROCESS_ON_EXIT_FAILED]_ 09-14 18:16:51.282 16527-16612/com.test.thalitest E/jxcore-log: Error: 09-14 18:16:51.282 16527-16612/com.test.thalitest E/jxcore-log: Cannot find module './CoordinatedClient' 09-14 18:16:51.282 16527-16612/com.test.thalitest E/jxcore-log: (module.js 802:9)

evabishchevich commented 8 years ago

There is a problem that files in the same directory can't see each other. We get

ERROR thaliTape: uncaught exception, error: 'Error: Cannot find module './CoordinatedClient'', stack: 'Error: Cannot find module './CoordinatedClient' at $w._oldRes@module.js:802:9 at $w._resolveFilename@module.js:1771:1 at @/data/data/com.test.thalitest/files/www/jxcore/lib/CoordinatedTape.js:14:1 at $w.prototype._compile@module.js:621:8 at $w._extensions[".js"]@module.js:651:1 at $w.prototype.load@module.js:442:1' while running the app.

These files presented into a builded apk but on device files/www/jxcore folder is epmty. This folder was empty in previous versions also so it's default behaviour.

I'm going to investigate what cordova makes with assets during building process.

evabishchevich commented 8 years ago

Needed files are in data/app/com.test.thalitest-1/base.apk. I installed our app on emulator, grabbed the apk and looked inside the apk.

evabishchevich commented 8 years ago

Still fighting with this problem. There are a lot of error if I change order of require modules. Also I found out that we use old jxcore in our build script. I'm going to change that and check with 0.1.4

yaronyg commented 8 years ago

We have a work around for this so we will put it into backlog for now.

yaronyg commented 8 years ago

The work around didn't work. Currently it seems like we can't have require chains that are more than 4 deep. We need to fix this ASAP.

enricogior commented 8 years ago

The problem doesn't show up on desktop but that is expected since in thaliTape.js, 'require('./CoordinatedTape');' is only called on mobile:

if (typeof jxcore === 'undefined' || typeof Mobile !== 'undefined') {
  // On mobile, or outside of jxcore (some dev scenarios)
  // we use the server-coordinated thaliTape.
  exports = require('./CoordinatedTape');
  exports.coordinated = true;
} else {
  // On desktop we just use simple non-coordinated tape.
  exports = require('./SimpleTape');
  exports.coordinated = false;
}
enricogior commented 8 years ago

Running the same code on Android using the standalone jxcore binary requires a few 'fixes' here and there, but overall it works and loads the CoordinatedClient without errors.

root@generic_x86:/data/local/tmp/thali/test # ../jx UnitTest_app.js
CoordinatedClient loaded
CoordinatedTape loaded
...
andrew-aladev commented 8 years ago

We can run jx runCoordinatedTests.js with CoordinatedTape on desktop.

enricogior commented 8 years ago

@andrew-aladev is it possible to run the Thali test app as a cordova app on desktop? Because running jx runCoordinatedTests.js is not what I need in the sense that even on Android I can run it and it doesn't fail to load the CoordinatedClient module.

yaronyg commented 8 years ago

@enricogior So are the tests actually passing when you run them on Android? How many phones do you have?

enricogior commented 8 years ago

At the current point of investigation, this seems a bug in the SpiderMonkey engine when running on ARM. The bug only shows up when using this code:

if (!Array.prototype.shuffle) {
  Array.prototype.shuffle = function () {...};
}

Replacing existing Array.prototype methods works, adding a new one has the side effect of causing the 'require()' bug.

yaronyg commented 8 years ago

This is obviously awful but we don't currently have a good way of debugging on ARM what exactly is going on so for the short term we are going to remove prototypes on Array objects (and other system objects) but eventually we have to run this to ground.

yaronyg commented 8 years ago

See the comment in thaliproject/Thali_CordovaPlugin#1123 about js-polyfill. But @enricogior, if the ponyfill work around works then we should still keep this bug on the backlog but we can come back to it later and now with a test case (js-polyfill) that will apparently blow up on the desktop.

yaronyg commented 8 years ago

For now we have a work around so we'll have to put it into icebox.