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 May 19 '16 at 12:48
  • No this is not an App, its normal aspx page added from SharePoint designer interface. – Nikhil Chavan May 19 '16 at 12:51
  • Have you done alternate access mapping on the environment? – Hardik May 19 '16 at 14:24

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. – Nikhil Chavan May 19 '16 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? – Ahmed Mahmoud May 19 '16 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 Jul 1 '16 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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