node-tar
node-tar copied to clipboard
Error when using in typescript
I'm working with typescript that's bundled using tsup
I'm getting this error:
throw Error('Dynamic require of "' + x + '" is not supported');
^
Error: Dynamic require of "events" is not supported
and I'm using tar like this
const archiveFile = path.join(targetDirectory, 'repository.tar.gz');
const archiveStream = fs.createWriteStream(archiveFile);
await new Promise((resolve, reject) => {
response?.body?.pipe(archiveStream);
response?.body?.on('error', reject);
archiveStream.on('finish', resolve);
});
// Extract the specific folder from the tarball
await fs.mkdir(targetDirectory, { recursive: true });
// Check if the archive file exists
await fs.promises.access(archiveFile);
// Proceed with extraction
await tar.x({
file: archiveFile,
cwd: targetDirectory,
strip: 1,
sync: true,
});