I had installed the plugin by following command in serverless 2.53.1.
npm install --save-dev serverless-s3-sync
After installing I had imported the plugin like this in serverless.yml
plugins:
- serverless-plugin-common-excludes
- serverless-plugin-include-dependencies
- serverless-python-requirements
- serverless-s3-sync
But (serverless deploy) is giving the following error. Screenshot of error is also attached. (This error only happens when I import this plugin of serverless-s3-sync in serverless.yml file other plugins are running fine).
ERROR DETAILS:
TypeError: Cannot read property 'defaultEncoding' of undefined at _write (node:internal/streams/writable:291:24) at WriteStream.Writable.write (node:internal/streams/writable:334:10) at NodejsStreamOutputAdapter.ondata (C:\serverless_v2\node_modules\readable-stream\lib_stream_readable.js:619:20) at NodejsStreamOutputAdapter.emit (node:events:394:28)
Here's a full error:
I got this error message twice from Serverless Framework. The error message is not descriptive for the root cause. The way I could resolve it was:
serverless plugin install -n serverless-s3-syncNow I could deploy the project again. But the error message is misleading and should be considered an error in itself that the error message is a source of painful confusion.
After a lot of digging, I isolated the cause to having two different versions of graceful-fs in the resolved node sub-dependencies.
In my case I'm using the serverless-python-requirements plugin, not serverless-s3-sync, but the error is the same. Both plugins list graceful-fs as a dependency.
You can see from yarn list that there are two different versions of graceful-fs installed:
% yarn list
├─ fs-extra@9.1.0
│ ├─ at-least-node@^1.0.0
│ ├─ graceful-fs@^4.2.0
│ ├─ jsonfile@^6.0.1
│ └─ universalify@^2.0.0
…
├─ graceful-fs@4.2.2 ← version used by fs-extra, required by jsonfile
…
├─ jsonfile@6.1.0
│ ├─ graceful-fs@^4.1.6
│ ├─ graceful-fs@4.1.15 ← version used by jsonfile
│ └─ universalify@^2.0.0
…
It seems that the stream objects created by one version of this library are not consumable by the other version.
With yarn I solved this by pinning graceful-fs to the latest version by adding this to my package.json file:
"resolutions": {
"**/graceful-fs": "4.2.8"
}
For npm it should be possible to achieve the same thing using npm-force-resolutions, but it appears the syntax is slightly different (I have not tested this):
"resolutions": {
"graceful-fs": "4.2.8"
}
Removing the lock file and node_modules folder and reinstalling might solve the problem, but given the pain this has caused, I was happier to pin the version in package.json.