Photoshop should never crash because of any script, so that indicates a Photoshop bug. Unfortunately there's not much we can do.
You can try resetting Photoshop preferences by holding alt+ctrl+shift (Windows) or shift+command+option (Mac) while you open Photoshop.
You could try uninstalling and reinstalling Photoshop.
Can you try an older version of Photoshop?
You could try an older version of the script. For example, here's 6.13 (just before we rewrote the script to be much faster):
https://raw.githubusercontent.com/EsotericSoftware/spine-scripts/c9f29df5734789420076c7224cf3dc02e9483e11/photoshop/PhotoshopToSpine.jsx
You could try replacing:
first: hasBackgroundLayer() ? 0 : 1,
With 0 (no background layer) or 1 (you have a background layer):
first: 0,