box / boxcli

A command line interface for interacting with the Box API.
https://developer.box.com
Apache License 2.0
222 stars 59 forks source link

fix: single file upload on Node 16 #441

Closed mhagmajer closed 1 year ago

mhagmajer commented 1 year ago

This fixes boxcli files:upload for single file upload (for files smaller than 100 MB) when working on Node 16.

Steps to test it:

  1. Make sure that you're on Node 12 (our package-lock.json is still in lockfileVersion: "1").
  2. Remove all the dependencies with rm -rf node_modules.
  3. Checkout this PR with git checkout mh/files_upload_node16.
  4. Reinstall dependencies with npm i, to make sure that you got the right versions from package.json and package-lock.json.
  5. Run a sample upload command to verify that it works on Node 12. I used this one ./bin/run files:upload [path] -p [parent-id] -n [name] -t [token]. Make sure that the file you're uploading is smaller than 100 MB, otherwise chunked upload will kick in which had no issues.
  6. Switch to Node 16. The same upload command should work now.

Explanation:

After many tests and long debugging I found out that the underlying problem was an old version of fs-extra library which somehow interfered with request used by box-node-sdk causing the ESOCKETTIMEOUT error. I solved it by bumping the dependency to the newest version compatible with Node 12 10.1.0 (making sure that that other dependencies can be on this newer version also) and limiting the uses of it in our code to just the tests (both these steps were necessary to fix it).

All tests on Node 12 pass after this code change, so the effect of this PR is that the upload will work on Node 16 while keeping the same behaviour on previous versions. Some other unrelated updates may be necessary to make all the tests work on Node 16 also.