Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Moving from 1.0.* to 2.0.*

Patrick Rodgers edited this page Jan 4, 2017 · 8 revisions

As we move to 2.0.0 it represents a breaking change from the 1.0.0 versions - though we've done our best to minimize the work on your end. That being said, read below as you may have some work to do in your solutions. This is meant to be a living document so if we missed a step please let us know - or update the article :).

Update Node to 6.9.* (latest LTS version)

This allows support for es6 modules in the lib folder as well as supporting a broad range of JavaScript modern features in node. The use of es6 modules also makes it possible to work with webpack 2 and other modern package managers to optimize your build. If you are concerned about compatibility with older projects you can use nvm or nvm-windows to manage multiple versions of node.

Update how you use NodeFetchClient or SPRequestExecutorClient

Previously there were individual settings used with the pnp.setup method to configure the node fetch client (for working in node) or the SPRequestExecutor (when working in add-in webs). These have been replaced with a single setting that takes a factory method for the fetch client you wish to use for your requests. This grants full control over what is executing your requests, and simplifies the setup of the library.

Setup NodeFetchClient

import { setup, Web, NodeFetchClient } from "sp-pnp-js";

setup({
    fetchClientFactory: () => {
        return new NodeFetchClient("{site url}", "{client id}", "{client secret}");
    }
});

let w = new Web("{site url}");

w.select("Title").get().then(w => {
    console.log(w);
});

Setup SPRequestExecutorClient

import { setup, sp, SPRequestExecutorClient } from "sp-pnp-js";

setup({
    fetchClientFactory: () => {
        return new SPRequestExecutorClient();
    }
});

let w = sp.crossDomainWeb("{add-in web url}", "{host web url}");

w.select("Title").get().then(w => {
    console.log(w);
});
Clone this wiki locally