Today I will talk about a problem concerning the use of PNP JS Core on an environment 2013 OnPremise.
Like many I started using PNP JS Core for my developments. After retrieving some information and doing some conclusive tests on an Office 365 environment, I wanted to reuse my code on a SharePoint 2013 OnPremise.
And there .. Boom!
SyntaxError: Unexpected token < in JSON at position 0
The code does not have anything complicated, it will only read the contents of a list.
Looking a bit, I saw that the return of the REST call was XML and not JSON. It seems that this comes from the basic configuration of SharePoint 2013 SP1 https://github.com/SharePoint/PnP-JS-Core/issues/125
The solution to this problem is to pass a configuration before making the call: https://github.com/SharePoint/PnP-JS-Core/pull/127
"Accept": "application/json; odata=verbose"
Simple but when you start using PNP JS it can be useful to know.
Hoping it helps.
NB : Thanks to Yannick for helping the noobie I was in this situation !