krpano.js error in strict-mode via webpack

  • Dear krpano Team,
    I tried to include the krpano.js via webpack, but it is throwing an error due to the automatically introduced strict-mode:
    "TypeError: Cannot set property length of [object Object] which has only a getter"

    Due to the heavy obfuscation of the js I don't wont to spend the time for reverse engeneering, but would love to see this fixed in one of the next versions of the file.

    Nowadays it is generally concidered good practise to have your code run in strict mode and it is supposed to also help performance: https://stackoverflow.com/questions/1335…oning-behind-it
    It would be also cool (but not nesessary), if the code could be wrapped a bit, so that it can be included using modern commonJs tools like webpack but still would work backwards compatible as standalone browser include:

    I'm happy to contribute a PR, but I guess you'll not want that ;)

    Best wishes
    Andreas

  • I know this is a really old thread, but was there ever a resolution to this? I'm hitting the exact same issue.

    Code
    Uncaught (in promise) TypeError: Cannot set property length of [object Object] which has only a getter    at krpano.js:219:1  at Object.embedpano (krpano.js:227:10) at gt (krpano.js:127:91) at yt (krpano.js:127:243) at d (krpano.js:168:1) at Object.embedpano (krpano.js:169:4)

    Using Typescript and Webpack.

  • Hi,

    due the 'dynamics' of the actions/object system using the strict mode is not possible. Some very important Javascript features are otherwise not available. That's intentional and not a bug and will not change.

    Generally strict mode should be always applied only to your own code and functions, never to third party stuff.

    Best regards,
    Klaus

  • Hi Klaus,

    I came across the same problem after manually converting the file to ESM format. It would seem that there is one issue, and that's the issue reported by andreas108. Inside the `krpano.js` code there is a line somewhere which sets the `arr.length = 0`. Setting the `length = 0` doesn't seem to work in some cases where strict is automatically applied.

    I was able to fix the problem by just adding one line of code right before the call to `arr.length = 0`, and that's this line: `Object.defineProperty(arr, "length", { writable: true });` which I got from here https://developer.mozilla.org/en-US/docs/Web…ts/Array/length

    It would be awesome if you would add this one line into the krpano.js file to avoid these problems from happening to customers who want to use ESM format.

    Thank you,
    Nick

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!