filestack / filestack-js

Official Javascript SDK for the Filestack API and content ingestion system.
https://www.filestack.com
MIT License
206 stars 77 forks source link

Client.upload function silently fails on Node.js when using Webpack. #385

Closed andrew-invoiced closed 3 years ago

andrew-invoiced commented 4 years ago

What kind of change does this PR introduce? Bug fix - Node.js/Webpack combination creates issue where Client.upload silently fails.

What is the current behavior? The S3Uploader class's 'execute' function silently fails after the line await this.startRequest(id) (line 109 in s3.ts) as a result of the HttpAdapter's call to getVersion from utils inside HttpAdapter's request function (line 94 in http.ts).

This error is specific to use with Webpack and node. It doesn't fail for Webpack/Browser combination because the browser module has the 'getVersion' function implemented using a static constant.

The Node 'getVersion' function currently uses a require statement at runtime to get the version from package.json. When using Webpack, the require statement points to a non-existent file path which causes the function to throw an error, thus causing the request to fail.

Current issue - Issue 286

What is the new behavior (if this is a feature change)? This PR has removed the require statment which is used to return the version and instead uses a constant defined by Webpack.DefinePlugin which already existed before this PR, and which the browser module uses to return the version.

The Client.upload function, and all other functions using HttpAdapter.request now work with a Node.js/Webpack combination.