koltyakov/sp-pnp-node

TypeError: global.fetch is not a function with sp-pnp-js 3.0.1

darrenparkinson opened this issue · 4 comments

When using sp-pnp-js 3.0.1, I get the error TypeError: global.fetch is not a function. Switching back to sp-pnp-js 2.0.7 resolves the issue.

Hey @darrenparkinson

Thanks for posting the issue!
I have not tested the lib with sp-pnp-js v 3.*
It definitely is not working now because of some structural changes.
Please stick with ver. 2.* of sp-pnp-js for a while.

I have the plans to make sp-pnp-node major update with sp-pnp-js v 3.* support, yet can't say any ETA.

Hi @darrenparkinson,

I've managed to figure out and fix the thing.
Actually, previous worked with sp-pnp-node ver. 3.0.1 nicely.

The issue was in the way, how pnp.setup is configured.
In 3.x the setup was split to separate settings for sp, graph and so on.

Anyway, ...
I've published

  • sp-pnp-node ver. 1.x for backward compatibility with sp-pnp-js ver. 2.x.
  • and sp-pnp-node ver. 2.x for sp-pnp-js ver. 3.x.

The main difference was in documentation and integration tests.

With sp-pnp-js ver. 2.x, the following code used to work:

pnp.setup({
    fetchClientFactory: () => {
        return new PnpNode(pnpNodeSettings);
    }
});

but with sp-pnp-js ver. 3.x it should be:

pnp.setup({
    sp: {
        fetchClientFactory: () => {
            return new PnpNode(pnpNodeSettings);
        }
    }
});

Actually, it's all the difference in the setup.
All integration tests for 2013, 2016 and SPO worked with sp-pnp-js ver. 3.0.1 as they should.

Could you please take a look?

Closing this. @darrenparkinson, feel free to reopen if you still have questions.

PnpNode is not defined