0

I have a string that I wish to compress in Svelte and to expand later in python. I am have problems importing lzip into Svelte

package.json

"dependencies": {
    ...
    "lzip": "^1.0.10",
    ...
}

App.Svelte

<script>
    import lzip from 'lzip.js';
    ...

I get the console message:

ReferenceError: lzip is not defined

And in the npm terminal

(!) Missing global variable name
Use output.globals to specify browser global variable names corresponding to external modules
lzip.js (guessing 'lzip')
Psionman
  • 3,084
  • 1
  • 32
  • 65

1 Answers1

0

I doubt that the lzip package you specified is what you want.

It is completely obscure and contains nothing but a bin script that does not export anything. It is thus not suitable for import anyway.

lzip itself does not sound like the correct choice either.

lzip is a free, command-line tool for the compression of data

You can't use a command line tool in the front end. If anything you have to install that on the server and only use on the server, definitely not in a .svelte file.

There are many other libraries that just compress data directly, so I doubt that you need lzip for that.

H.B.
  • 166,899
  • 29
  • 327
  • 400
  • Ok. Any recommendations? – Psionman Aug 18 '23 at 08:00
  • I have used [`jszip`](https://www.npmjs.com/package/jszip) before. – H.B. Aug 18 '23 at 08:02
  • my string is not in a file; [lz-string](https://pieroxy.net/blog/pages/lz-string/index.html)? – Psionman Aug 18 '23 at 08:11
  • Possibly, StackOverflow does not allow questions that ask for recommendations; you will just have to do your own research into finding something suitable for your requirements. – H.B. Aug 18 '23 at 08:21
  • (The string does not have to be in a file either, I only ever used `jszip` to generate ZIP files directly from memory. Of course you do end up with a ZIP archive containing files, which would need to be unwrapped again.) – H.B. Aug 18 '23 at 08:23
  • got it working with lz-string - now to decompress using python ... – Psionman Aug 18 '23 at 09:07