4

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:

enter image description here

bilal
  • 41
  • 3

2 Answers2

3

After a lot of digging, I isolated the cause to having multiple incompatible 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 three different versions of graceful-fs installed:

% yarn list

├─ fs-extra@9.1.0
│  ├─ at-least-node@^1.0.0
│  ├─ graceful-fs@^4.2.0 ← version used by fs-extra
│  ├─ jsonfile@^6.0.1
│  └─ universalify@^2.0.0
…
├─ graceful-fs@4.2.2 ← version directly declared in package.json
…
├─ 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.

Guy
  • 632
  • 5
  • 8
2

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:

  • Delete the two directories named (1) node_modules and (2) .serverless
  • Reinstall the dependencies using serverless instead of npm e.g. serverless plugin install -n serverless-s3-sync

Now 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.

Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424