Loading external lib recently broke + XSLX import workaround


I was using some external library in a pre-request script like so :

pm.sendRequest(`https://unpkg.com/xlsx@0.16.6/dist/xlsx.full.min.js`, (err, res) => {
    // now using lib
    var wb = XLSX.utils.book_new();
    // ...


Worked nicely (I think I recently allowed postman update), but now it fails with “TypeError: Cannot set property ‘JSZipSync’ of undefined”
I searched for the cause in the loaded script and found that the zip lib included in the js script try to set the JSZipSync of either window, self, global, globalThis or $.global so that it can be found by consuming code of XLSX.

So probably one of them was defined before in postman environment, it si no longer the case.
Do you have similar issue ? And maybe a trick to work around this ?

Thanks !

postman version : 7.35.0

Hey @fsarron-ext,
I tried the snippet you sent with the solution suggested in a previous thread. This should help.

window = {};
pm.sendRequest(https://unpkg.com/xlsx@0.16.6/dist/xlsx.full.min.js, (err, res) => {
// now using lib
var wb = XLSX.utils.book_new();


Thanks a lot for your answer Meena,

This definition of window allow the jszip lib to properly attach on window, avoiding the error, but XLSX lib later seem to fail using it, silently producing invalid xlsx file. I need to investigate further.


For people encountering the same particular issue, here the workaround I came up with :

pm.sendRequest(`https://www.unpkg.com/xlsx@0.16.8/dist/jszip.js`, (err, res) => {

    window = {}; // for jszip to attach

    pm.sendRequest(`https://www.unpkg.com/xlsx@0.16.8/dist/xlsx.js`, (err, res) => {

        JSZipSync = window.JSZipSync // for XLSX to catch

        // use XSLX

Dont get the full version of XLSX, take jszip first then xlsx