When I run npm publish
command, I get the below error at the end.
npm notice
npm notice 📦 @my_scope/my-package@2.0.156
npm notice === Tarball Contents ===
npm notice <size> <file>
npm notice <size> <file>
npm notice <size> <file>
...
npm notice filename: @my_scope/my-package-2.0.156.tgz
npm notice package size: 1.8 GB
npm notice unpacked size: 1.8 GB
npm notice shasum: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
npm notice integrity: sha512-XXXXXXXXXXX[...]XXXXXXXXXXXX==
npm notice total files: 333
npm notice
npm notice Publishing to https://xxxxxxxxxxxx
npm ERR! code ERR_STRING_TOO_LONG
npm ERR! Cannot create a string longer than 0x1fffffe8 characters
What does this mean and how can I resolve it?
ERR_STRING_TOO_LONG
means that an attempt has been made to create a string longer than the maximum allowed length.
0x1fffffe8
means 512MB, which is the maximum allowed length for the above case.
The npm publish command tries to create a tarball with contents inside your package folder and convert that tarball data into a base64 encoded string. And in this case, it has become larger than the maximum allowed length (512MB), which caused this error too.
To fix this, carefully inspect the contents output with npm notice <size> <file>
and remove the unnecessary data inside your package (e.g. cache folder ~/.npm/_cacache/
).
References: