none
Azure service issues? "Cannot find module" when referencing Shared script

    Question

  • Is anything going on with Mobile Services right now? Just today I started having an exception occur when calling mobile service scripts that rely on a shared script. Here is the exception I get:

    Error in script '/table/Mytable.read.js'. Error: Cannot find module '../shared/mysharedscript' [external code] at read (</table/Mytable.read.js>:4:18) at </table/Mytable.read.js>:1:6 [external code]

    However, when I browse my service using PowerShell, I definitely see my shared script in the service.

    data:    Name              Size
    data:    ----------------  ----
    data:    shared/mysharedscript.js  890 


    What has changed that would be causing this issue? Because of this, users of my app are having issues.

    Wednesday, April 09, 2014 12:41 PM

Answers

  • Hi Tim,

    I can confirm that there is a bug that causes the shared scripts to be lost periodically if you do NOT have source control enabled.  For the short term, if you can enable source control you should not encounter this problem.  Source control will be turned on by default for everyone in the next couple months, so this is what I'd recommend.

    I believe the documentation should have the caveat I mentioned (you must have source control enabled for your Mobile Service).  Without source control, you are only supposed to be able to upload the APNS feedback script that also lives in the /shared scripts folder through the CLI.  With it, you can use git or the CLI to upload your scripts.

    • Marked as answer by TimSF Friday, April 18, 2014 12:25 AM
    Thursday, April 17, 2014 8:07 PM
    Moderator
  • Here is our guide on setting up source control: http://azure.microsoft.com/en-us/documentation/articles/mobile-services-store-scripts-source-control/

    You'll just need to do the first part, "Enable source control in your mobile service".  The rest is optional, you can continue to use your current workflows for modifying scripts with the CLI.

    You can also use the CLI, "azure mobile preview enable <mobileservice> sourcecontrol" to turn it on.  Although if you haven't set up your user credentials before (for websites or mobile services) you will want to use the portal to specify those.

    • Marked as answer by TimSF Friday, April 18, 2014 12:26 AM
    Thursday, April 17, 2014 11:09 PM
    Moderator

All replies

  • Alright - I just download the shared script and upload it (the same exact file!) again and now it immediately started working again. Why is that the case?

    I'm using shared scripts for a production release and I'd like to know whether this will be a recurring issue or if I need to do something different to ensure that it works consistently. From the other recent post by Lukas C it sounds as if this is not the first time this has occurred. Thanks.


    • Edited by TimSF Wednesday, April 09, 2014 4:02 PM
    Wednesday, April 09, 2014 3:24 PM
  • For a second time in a week, my table scripts were unable to access my shared script last night even though I hadn't done anything to the shared script since the last occurrence of this problem (a couple days ago).

    Error in script '/table/Mytable.read.js'. Error: Cannot find module '../shared/mysharedscript' [external code] at read (</table/Mytable.read.js>:4:18) at </table/Mytable.read.js>:1:6 [external code]

    I had to upload the same exact shared script (overwriting the existing one) for the table scripts to acces the shared script.

    Why does this keep happening? If shared scripts in Azure are unreliable, I'd like to know so I can make alternate plans. Thanks. 

    Saturday, April 12, 2014 11:34 AM
  • Do you have source control enabled for your mobile service?  Shared scripts require having it enabled, but unfortunately we appear to have a bug in the CLI letting you upload shared scripts w/o having SC enabled. 

    Thursday, April 17, 2014 7:05 AM
    Moderator
  • Thanks, Phillip. I do not have source control enabled, but the Microsoft documentation seems to indicate that source control is not required. Refer to:

    http://azure.microsoft.com/en-us/documentation/articles/mobile-services-how-to-use-server-scripts/#how-to-use-helper-functions

    In that document the following statement is made with respect to shared scripts: "Script files are uploaded to the shared directory either by using source control or by using the command line tool."

    In my case, I've used the command line tool. Can you comment on this? Thanks, again.

    Thursday, April 17, 2014 12:15 PM
  • Hi Tim,

    I can confirm that there is a bug that causes the shared scripts to be lost periodically if you do NOT have source control enabled.  For the short term, if you can enable source control you should not encounter this problem.  Source control will be turned on by default for everyone in the next couple months, so this is what I'd recommend.

    I believe the documentation should have the caveat I mentioned (you must have source control enabled for your Mobile Service).  Without source control, you are only supposed to be able to upload the APNS feedback script that also lives in the /shared scripts folder through the CLI.  With it, you can use git or the CLI to upload your scripts.

    • Marked as answer by TimSF Friday, April 18, 2014 12:25 AM
    Thursday, April 17, 2014 8:07 PM
    Moderator
  • Thanks, again. Can you point me to a good link that has an accurate step-by-step for installing source control for this?
    Thursday, April 17, 2014 8:20 PM
  • Here is our guide on setting up source control: http://azure.microsoft.com/en-us/documentation/articles/mobile-services-store-scripts-source-control/

    You'll just need to do the first part, "Enable source control in your mobile service".  The rest is optional, you can continue to use your current workflows for modifying scripts with the CLI.

    You can also use the CLI, "azure mobile preview enable <mobileservice> sourcecontrol" to turn it on.  Although if you haven't set up your user credentials before (for websites or mobile services) you will want to use the portal to specify those.

    • Marked as answer by TimSF Friday, April 18, 2014 12:26 AM
    Thursday, April 17, 2014 11:09 PM
    Moderator
  • Thank you, that is good to know. Unfortunately, I'm trying to enable it right now (from within the portal) and I'm getting the following error: "Failed to enable source control for MyService. Error 500." I've tried twice now with the same error. What should I do in this case?
    Friday, April 18, 2014 12:04 AM
  • Ok - the third time it worked. The first two times it didn't prompt me for a password and then failed. The third time it did prompt for a password and succeeded. Thank you, again, for your help.
    Friday, April 18, 2014 12:16 AM
  • One last thing: as soon as I enabled source control, my existing shared script was deleted. So I had to upload it again.
    Friday, April 18, 2014 12:22 AM