I have created a new aspx page from SharePoint Designer 2013 and I have following scripts added on my page head section. The page does not belong to any app, it is separate Wiki page, added from SharePoint Designer interface.

enter image description here

In App.js file I have following code:

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', 
function (){
 //your code goes here...
 alert('script loaded');
      var context = new SP.ClientContext.get_current();
     var user = context.get_web().get_currentUser();

When I open page in browser It is giving me following error: sp.js:2 Uncaught TypeError: Cannot read property 'webServerRelativeUrl' of undefined

And I have no idea what I am missing or whats wrong with my code. Please can somebody explain this behavior.


  • is this an app?
    – Hardik
    Commented May 19, 2016 at 12:48
  • No this is not an App, its normal aspx page added from SharePoint designer interface. Commented May 19, 2016 at 12:51
  • Have you done alternate access mapping on the environment?
    – Hardik
    Commented May 19, 2016 at 14:24

2 Answers 2


Try to use ExecuteOrDelayUntilScriptLoaded instead. something like this

ExecuteOrDelayUntilScriptLoaded(init, "sp.js");

function init() 
            this.clientContext = new SP.ClientContext.get_current();
            this.oWeb = clientContext.get_web();
            currentUser = this.oWeb.get_currentUser();
            this.clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

  • I tried this too, but I am getting same error. Commented May 19, 2016 at 12:55
  • did you try just embed your code in a Script Editor on any page and see if it works or not? Can you share a screen shot of the console? Commented May 19, 2016 at 13:02

You need to remove unnecessary script tag from your header which is after sp.js

You need to place it before the runtime.js

Please check this below given URL.

It is having the same Issue & got the resolution as an answer.

SP.PageContextInfo.get_webServerRelativeUrl uncaught TypeError

  • Did you tried it? Is it working for you?
    – Hardik
    Commented Jul 1, 2016 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.