isaacs / node-tar

tar for node
ISC License
837 stars 183 forks source link

Error when using in typescript #397

Closed TheMikeyRoss closed 6 months ago

TheMikeyRoss commented 10 months ago

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,
        });
isaacs commented 6 months ago

Version 7 is a typescript rewrite, so this will no longer be an issue.