Stack Overflow Asked on December 23, 2021
I’m trying to use libarchive.js to decompress a zip file that protected by a password.
import {Archive} from 'libarchive.js/main.js';
Archive.init({
workerUrl: 'libarchive.js/dist/worker-bundle.js'
});
document.getElementById('file').addEventListener('change', async (e) => {
const file = e.currentTarget.files[0];
const archive = await Archive.open(file);
let obj = await archive.extractFiles();
console.log(obj);
});
When I run this code, the console shows below output.
I have tried many workerUrl like below. But the result is same.
workerUrl: 'libarchive.js/dist/worker-bundle.js'
workerUrl: '/libarchive.js/dist/worker-bundle.js'
workerUrl: '../libarchive.js/dist/worker-bundle.js'
workerUrl: '../../libarchive.js/dist/worker-bundle.js'
workerUrl: '/node_modules/libarchive.js/dist/worker-bundle.js'
workerUrl: '../node_modules/libarchive.js/dist/worker-bundle.js'
workerUrl: '../../node_modules/libarchive.js/dist/worker-bundle.js'
What is the problem?
Thanks.
I used this code.
Archive.init({
workerUrl: '/libarchive.js/dist/worker-bundle.js',
});
And I put libarchive.js in /public folder of my Vue project. It worked.
Answered by Raymond on December 23, 2021
Whenever you see this:
▶ Uncaught SyntaxError: Unexpected token '<' some-file.js:1
It's usually because the request to load some-file.js
returned an HTML page displaying a 404
error, but it's being interpreted as JavaScript and crashing on the very first character, which in the source of an HTML page is usually <
.
To solve your problem, you can try the following URL from this answer:
/lib/worker-bundle.js
Or you can try to view worker-bundle.js
directly in a browser. Either you will locate the correct URL, or you will learn that your server is simply not serving that file at all.
Answered by GirkovArpa on December 23, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP