2

I installed aws-s3-zipper using npm, after that, I am getting this error.

This is my code:

AWS = require("aws-sdk");
var S3Zipper = require("aws-s3-zipper");

function zipFolderOnS3() {

    var zipper = new S3Zipper(config);

    return new Promise((resolve, reject) => {
        var config = {
            accessKeyId: process.env.ACCESS_KEY_ID,
            secretAccessKey: process.env.SECRET_ACCESS_KEY,
            region: process.env.REGION,
            bucket: process.env.BUCKET_NAME
        };
        var zipper = new S3Zipper(config);
        try {
            zipper.zipToS3FileFragments({
                s3FolderName: "Documents"
                , MaxFileCount: 50
                //, startKey: ‘keyOfLastFileIZipped' // optional
                , S3ZipFileName: "Documents.zip",
                recursive: true
            }, function (err, result) {
                if (err) {
                    console.error(err);
                }
                else {
                    console.error("File uploaded on s3");
                }
            });
        } catch (e) {
            console.log(e)
        }
    });
}

module.exports = {
    zipFolderOnS3
};
Andrew Hardiman
  • 929
  • 1
  • 15
  • 30
spirits
  • 31
  • 4
  • perhaps it's related to this? https://stackoverflow.com/questions/55921442/how-to-fix-referenceerror-primordials-is-not-defined-in-node – andersryanc Nov 03 '20 at 06:14
  • or maybe `aws-s3-zipper` depends on `graceful-fs`? https://intellij-support.jetbrains.com/hc/en-us/community/posts/360007646780-How-to-fix-ReferenceError-primordials-is-not-defined-error- – andersryanc Nov 03 '20 at 06:15
  • no.., I am not using graceful-fs – spirits Nov 03 '20 at 06:18
  • `aws-s3-zipper` depends on `s3` [node-s3-client](https://github.com/andrewrk/node-s3-client/blob/master/package.json) which has a dependency of `graceful-fs` – andersryanc Nov 03 '20 at 06:18
  • there is an open issue about node12 in the node-s3-client github: https://github.com/andrewrk/node-s3-client/issues/228 – andersryanc Nov 03 '20 at 06:19

4 Answers4

4

aws-s3-zipper depends on s3 node-s3-client which has a dependency of graceful-fs which (the version currently included by s3@4.4.0) has issues/incompatibilities with node v12 and above.

According to this graceful-fs v4.2.2 is known to work with node 12...

What really needs to happen, is that node-s3-client needs to update their dependency of graceful-fs. There is already an open github issue for this, in which someone suggested to use @auth0/s3.

So, you could either try and get aws-s3-zipper to switch to using that until the official package is updated... OR... aws-s3-zipper is only a single file, so you could also just copy in that to your project.

Here is what I was able to get working:

  1. first update your deps
npm uninstall aws-s3-zipper
npm install @auth0/s3 archiver
  1. copy the index.js source code from aws-s3-zipper into a new file in your project, like ./aws-s3-zipper.js.

  2. update your require statements in your file:

// you can remove the AWS require as it's not actually used at all here
// AWS = require("aws-sdk");

// make this a relative path instead of including the package
var S3Zipper = require("./aws-s3-zipper");
  1. finally, fix the dependency issue in ./aws-s3-zipper.js that you copied down:
var assert = require('assert');
var archiver = require('archiver');
var async = require('async');
var AWS = require('aws-sdk');
var fs = require('fs');
// change `s3` to `@auth0/s3`
var s3 = require('@auth0/s3');

// ... the rest of the package

I commented on this GitHub issue in the aws-s3-zipper repo thinking they might be having the same issue and to see if they might switch to @auth0/s3 for the time being.

andersryanc
  • 939
  • 7
  • 19
0

Update the dependency in s3 from graceful-fs": "~3.0.5", to "graceful-fs": "^4.2.6",

it resolved for me

Saad Mujeeb
  • 49
  • 1
  • 1
  • 3
0

From this issue - https://github.com/andrewrk/node-s3-client/issues/236

Add the following to your package.json file so s3 can work with node > 12.

  "resolutions": {
    "graceful-fs": "4.x.x"
  },
Asen Mitrev
  • 633
  • 3
  • 10
0

As others mentioned, you have to upgrade graceful-fs, but I had to modify my package-lock manually and then run npm install.

    "node_modules/s3/node_modules/graceful-fs": {
      "version": "4.2.11",
      "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
      "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ=="
    },
Raine Revere
  • 30,985
  • 5
  • 40
  • 52