跳至内容

AWS CodeArtifact `npm publish` Fails with E400 Due to Max String Length – Known Limitation?

0

We are using AWS CodeArtifact as the artifact repository for our JavaScript frontend libraries. During a recent CI/CD pipeline run, the npm publish step failed with the following error:

npm ERR! code E400
npm ERR! 400 Bad Request - PUT https://<domain>.d.codeartifact.<region>.amazonaws.com/npm/<repo-name>/@<scope>%2f<package> - Bad request. Error parsing input. String value length (20054016) exceeds the maximum allowed (20000000, from `StreamReadConstraints.getMaxStringLength()`)

The error occurred while attempting to publish a scoped package approximately 23.9 MB in tarball size and over 100 MB when unpacked. The largest individual files were sourcemaps (*.js.map) exceeding 33 MB each.

This same package was published successfully to a Nexus repository without any errors or additional configuration.


Questions:

  1. Is this 20MB per-string limit (StreamReadConstraints.getMaxStringLength()) a documented or known limitation in AWS CodeArtifact?
  2. Is there any recommended workaround or setting in CodeArtifact to support large packages, especially those with heavy sourcemaps?
  3. Would excluding .map files or splitting the package be the only workaround, or is there an AWS-supported method to accommodate these files?

Tarball Summary from npm publish Output

Package: @<scope>/library-name
Version: 1.0.8
Tarball size: 23.9 MB
Unpacked size: 102.0 MB
Largest files:
- dist/index.cjs.js.map     ~33.0 MB
- dist/index.es.js.map      ~33.1 MB
- dist/index.umd.js.map     ~33.0 MB

package.json Structure

{
  "name": "@<scope>/library-name",
  "version": "1.0.8",
  "main": "./dist/index.cjs.js",
  "module": "./dist/index.es.js",
  "types": "./dist/index.d.ts",
  "files": ["dist"],
  "scripts": {
    "build": "tsc && vite build",
    "prepublishOnly": "npm run build",
    "publish:codeartifact": "npm publish --access=restricted"
  },
  "dependencies": {
    "@radix-ui/react-*": "...",
    "react": "^19.0.0",
    "vite": "^6.2.0"
  },
  "devDependencies": {
    "rollup": "...",
    "typescript": "~5.7.2",
    "vite-plugin-dts": "^4.5.3"
  }
}

Please advise if this limit is adjustable or if a different package handling approach is recommended.

已提问 5 个月前480 查看次数
1 回答
0

The error you're encountering is related to a known limitation in AWS CodeArtifact for npm package publishing. While CodeArtifact has an asset file size maximum quota that can be increased through a quota request, there is a specific limitation for npm packages that cannot be bypassed:

The maximum size of a publishing request for npm packages is 2 GB. However, this is not the only limitation at play in your case. In npm publishing requests, package metadata and the content of the npm package tar archive are bundled together, and there appears to be a string length limitation of 20 million characters that's causing your error.

This string length limitation is separate from the overall asset size quota and is likely related to how CodeArtifact processes the npm package data internally.

For your specific issue with large sourcemaps, here are some recommended approaches:

  1. Exclude sourcemaps from your published package by modifying your build configuration or adding them to .npmignore

  2. Split your package into smaller, more manageable packages

  3. Consider using source map optimization tools to reduce their size before publishing

  4. If you need to keep the large files, you might need to continue using Nexus or another repository solution that doesn't have the same string length constraints

Unlike Lambda functions (which have a hard 250 MB unzipped size limit), CodeArtifact's general asset size quotas can be increased, but this specific npm string length limitation appears to be a fixed constraint in how CodeArtifact processes npm packages.

The error you're seeing is not directly related to the overall package size but rather to how npm packages are processed during publishing to CodeArtifact.
Sources
Packages overview - CodeArtifact
Unzipped size must be smaller than 262144000 bytes | AWS re:Post
Quotas in AWS CodeArtifact - CodeArtifact

已回答 5 个月前
  • Is there any official AWS documentation that points to this particular string length limitation

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。